picgo
Version:
A tool for image uploading
38 lines (37 loc) • 2.12 kB
TypeScript
import type { IPicGo, MultipartCompletedPart, MultipartSession } from '../../../../types';
/**
* Persistent storage for in-flight multipart upload sessions — used to support resume
* across process crashes / restarts.
*
* Layout: a single JSON file `picgo-cloud-multipart-pending.json` under ctx.baseDir.
* The top level carries a `v: 1` schema version for future migrations. Sessions are keyed
* by `${userId}:${fingerprint}` so accounts switched on the same machine cannot collide.
*
* Design principle: missing file / corrupt JSON / write failure → silently degrade to
* "no resume". Persistence is nice-to-have, never a hard requirement; storage failures
* must never block the actual upload flow.
*/
export declare class MultipartStorage {
private readonly ctx;
constructor(ctx: IPicGo);
/** Look up a session by (userId, fingerprint). Returns null if missing / expired / unreadable. */
get(userId: string, fingerprint: string): MultipartSession | null;
/** Write or replace a session. Write failures are swallowed (resume is not a hard requirement). */
set(userId: string, fingerprint: string, session: MultipartSession): void;
/** Remove a session by (userId, fingerprint). No-op if the entry doesn't exist. */
remove(userId: string, fingerprint: string): void;
/** Append a completed part; if the same partNumber already exists it is replaced (retry case). */
appendCompletedPart(userId: string, fingerprint: string, part: MultipartCompletedPart): void;
/** Sweep sessions whose createdAt is older than (now - 7d). Boundary: entries at exactly 7d are kept. */
sweepExpired(now?: number): void;
/** List every session for the given userId in insertion order. */
listForUser(userId: string): Array<{
fingerprint: string;
session: MultipartSession;
}>;
private getFilePath;
/** Read the file; missing / parse failure / schema mismatch all collapse to an empty store. */
private read;
/** Atomic write; failures swallowed (resume is not a hard requirement and must not block uploads). */
private write;
}