1 import type { UseCaseInterface } from '../Domain/UseCase/UseCaseInterface'
2 import { Result } from '@proton/docs-shared'
3 import type { NodeMeta, PublicNodeMeta, DecryptedNode } from '@proton/drive-store'
4 import { getErrorString } from '../Util/GetErrorString'
5 import { isPublicNodeMeta } from '@proton/drive-store/lib/interface'
6 import type { DocumentMetaInterface } from '@proton/docs-shared'
7 import type { DriveCompatWrapper } from '@proton/drive-store/lib/DriveCompatWrapper'
11 refreshedDocMeta?: DocumentMetaInterface
14 export class GetNode implements UseCaseInterface<GetNodeResult> {
15 constructor(private compatWrapper: DriveCompatWrapper) {}
18 nodeMeta: NodeMeta | PublicNodeMeta,
19 docMetaToRefresh?: DocumentMetaInterface,
20 ): Promise<Result<GetNodeResult>> {
22 const node = isPublicNodeMeta(nodeMeta)
23 ? await this.compatWrapper.publicCompat?.getNode(nodeMeta)
24 : await this.compatWrapper.userCompat?.getNode(nodeMeta)
27 return Result.fail('Incorrect compat used; node not found')
30 if (docMetaToRefresh) {
31 const newDocMeta = docMetaToRefresh.copyWithNewValues({ name: node.name })
32 return Result.ok({ node, refreshedDocMeta: newDocMeta })
35 return Result.ok({ node })
37 return Result.fail(getErrorString(error) ?? 'Failed to get node')