1 import type { DecryptCommit } from './DecryptCommit'
2 import type { UseCaseInterface } from '../Domain/UseCase/UseCaseInterface'
3 import { Result } from '@proton/docs-shared'
4 import type { NodeMeta, PublicNodeMeta } from '@proton/drive-store'
5 import type { GetCommitData } from './GetCommitData'
6 import type { DecryptedCommit } from '../Models/DecryptedCommit'
7 import type { SessionKey } from '@proton/crypto'
10 * Fetches commit data from the Docs server and decrypts it
12 export class LoadCommit implements UseCaseInterface<DecryptedCommit> {
14 private getCommitData: GetCommitData,
15 private decryptCommit: DecryptCommit,
19 lookup: NodeMeta | PublicNodeMeta,
21 documentContentKey: SessionKey,
22 ): Promise<Result<DecryptedCommit>> {
23 const commitDataResult = await this.getCommitData.execute(lookup, commitId)
24 if (commitDataResult.isFailed()) {
25 return Result.fail(`Failed to get commit data ${commitDataResult.getError()}`)
28 const commit = commitDataResult.getValue()
30 const decryptResult = await this.decryptCommit.execute({
36 if (decryptResult.isFailed()) {
37 return Result.fail(`Failed to decrypt commit ${decryptResult.getError()}`)
40 return Result.ok(decryptResult.getValue())