1 import type { UseCaseInterface } from '../Domain/UseCase/UseCaseInterface'
2 import { Result } from '@proton/docs-shared'
3 import type { DocsApi } from '../Api/DocsApi'
5 import type { DocumentMetaInterface } from '@proton/docs-shared'
6 import { DocumentMeta } from '../Models/DocumentMeta'
7 import type { NodeMeta, PublicNodeMeta } from '@proton/drive-store'
10 * Primarily used to look up the CommitIds for a document, so that we can fetch the binary for the commits.
12 export class GetDocumentMeta implements UseCaseInterface<DocumentMetaInterface> {
13 constructor(private docsApi: DocsApi) {}
15 async execute(lookup: NodeMeta | PublicNodeMeta): Promise<Result<DocumentMetaInterface>> {
16 const result = await this.docsApi.getDocumentMeta(lookup)
17 if (result.isFailed()) {
18 return Result.fail(result.getError().message)
21 const data = result.getValue().Document
23 const meta = new DocumentMeta(data.VolumeID, data.CommitIDs, data.CreateTime, data.ModifyTime, '')
25 return Result.ok(meta)