MCPcopy Create free account
hub / github.com/ProtonDriveApps/sdk / commitDraft

Method commitDraft

client/js/src/internal/upload/manager.ts:380–424  ·  view source on GitHub ↗
(
        nodeRevisionDraft: NodeRevisionDraft,
        manifest: Uint8Array<ArrayBuffer>,
        extendedAttributes: {
            modificationTime?: Date;
            size: number;
            blockSizes: number[];
            digests: {
                sha1: string;
            };
        },
        additionalExtendedAttributes?: object,
        integrityInfo?: { checksumVerified: boolean },
    )

Source from the content-addressed store, hash-verified

378 this.logger.error('Failed to delete draft node revision', error);
379 }
380 }
381
382 async commitDraft(
383 nodeRevisionDraft: NodeRevisionDraft,
384 manifest: Uint8Array<ArrayBuffer>,
385 extendedAttributes: {
386 modificationTime?: Date;
387 size: number;
388 blockSizes: number[];
389 digests: {
390 sha1: string;
391 };
392 },
393 additionalExtendedAttributes?: object,
394 integrityInfo?: { checksumVerified: boolean },
395 ): Promise<void> {
396 const generatedExtendedAttributes = generateFileExtendedAttributes(
397 extendedAttributes,
398 additionalExtendedAttributes,
399 );
400 const nodeCommitCrypto = await this.cryptoService.commitFile(
401 nodeRevisionDraft.nodeKeys,
402 manifest,
403 generatedExtendedAttributes,
404 );
405 try {
406 await this.apiService.commitDraftRevision(nodeRevisionDraft.nodeRevisionUid, {
407 ...nodeCommitCrypto,
408 ...integrityInfo,
409 });
410 } catch (error: unknown) {
411 // Commit might be sent but due to network error no response is
412 // received. In this case, API service automatically retries the
413 // request. If the first attempt passed, it will fail on the second
414 // attempt. We need to check if the revision was actually committed.
415 let isRevisionUploaded;
416 try {
417 isRevisionUploaded = await this.apiService.isRevisionUploaded(nodeRevisionDraft.nodeRevisionUid);
418 } catch (catchError: unknown) {
419 this.logger.warn(`Failed to check if revision was committed: ${getErrorMessage(catchError)}`);
420 throw error; // Throw original error, not the checking one.
421 }
422 if (!isRevisionUploaded) {
423 this.logger.debug(`Revision was not committed`);
424 throw error;
425 }
426 this.logger.warn(`Node commit failed but node was committed successfully ${nodeRevisionDraft.nodeUid}`);
427 }

Callers 2

manager.test.tsFile · 0.80
commitFileMethod · 0.80

Calls 6

notifyNodeUploadedMethod · 0.95
commitDraftRevisionMethod · 0.80
isRevisionUploadedMethod · 0.80
warnMethod · 0.65
commitFileMethod · 0.45

Tested by

no test coverage detected