UNPKG

picgo

Version:

A tool for image uploading

50 lines (49 loc) 2.5 kB
import type { FileUploadResult } from '../FileService'; import type { ICloudUploaderManager, IImgInfo, ILogger, IPicGo, MultipartSession } from '../../../../types'; import { AuthRequestClient } from '../../Request'; import { MultipartStorage } from './MultipartStorage'; /** * PicGo Cloud multipart upload service. Two responsibilities: * * 1. **State machine** (`runMultipartUpload` function, called by FileService's size dispatch): * initiate → concurrent part PUTs → complete, with local session persistence so a crashed / * interrupted upload can resume on the next attempt for the same file. * * 2. **Management API** (this class's abort / listPending / removePending): exposed to picgo-gui * for a future "clean up pending uploads" UI. Mounted on `ctx.cloud.uploader`. * * Sessions left over by failure / crash are double-protected: server-side R2 lifecycle cleans * orphan multipart uploads after 7 days, local TTL also sweeps after 7 days. We intentionally * do NOT abort the remote session on state-machine failure, otherwise resume would be defeated. */ export declare class MultipartUploadService implements ICloudUploaderManager { private readonly ctx; private readonly authClient; private readonly storage; private readonly diagLogger; constructor(ctx: IPicGo); /** * Best-effort abort of a remote multipart upload session. * Swallows all errors (R2's 7-day lifecycle is the safety net); callers don't need try/catch. */ abort(uploadId: string, objectKey: string): Promise<void>; /** List all local pending multipart sessions belonging to the currently logged-in user. */ listPending(): MultipartSession[]; /** Delete only the local entry; does not notify the remote (call abort for that). */ removePending(fingerprint: string): void; /** @internal */ getInternals(): { ctx: IPicGo; authClient: AuthRequestClient; storage: MultipartStorage; diagLogger: ILogger | undefined; }; } /** * Run a full multipart upload: fingerprint → get/create session → concurrent part uploads → complete. * Called by FileService.upload when buffer size >= MULTIPART_THRESHOLD_BYTES. * * Deliberately not exposed on `ctx.cloud.uploader`: GUI / external plugins should go through * FileService so the size dispatch (single-PUT vs multipart) stays in one place. */ export declare function runMultipartUpload(ctx: IPicGo, img: IImgInfo): Promise<FileUploadResult>;