@adonis-agora/media
Version:
Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a
127 lines • 4.99 kB
TypeScript
import type { Readable } from 'node:stream';
import type { StorageManager } from './storage_manager.js';
import type { MultipartPart } from './types.js';
import { type ResolvedUploadMode, type UploadMode } from './upload_mode.js';
export interface UploadManagerOptions {
storage: StorageManager;
/** Global default upload mode (`auto` when omitted). */
mode?: UploadMode | undefined;
/** Default part size in bytes for direct multipart uploads. Default 8 MiB. */
partSize?: number | undefined;
/** Lifetime of presigned part URLs, in seconds. Default 3600. */
presignTtlSeconds?: number | undefined;
/** Emit `upload.*` diagnostics events (default true). */
emitDiagnostics?: boolean | undefined;
}
export interface InitiateDirectUploadInput {
/** Disk name; defaults to the manager's default disk. */
disk?: string;
/** Object key to write. Resolve this server-side (never trust the client) in your route. */
key: string;
/** Content-Type stamped on the final object. */
contentType?: string;
/** Public/private visibility for the final object. */
visibility?: 'public' | 'private';
/** Total size in bytes — used to pre-compute how many part URLs to hand back. */
size?: number;
/** Override the part size for this upload. */
partSize?: number;
}
export interface DirectUploadCreated {
uploadId: string;
key: string;
disk: string;
partSize: number;
parts: {
partNumber: number;
url: string;
}[];
}
export interface PresignPartInput {
disk?: string;
key: string;
uploadId: string;
partNumber: number;
}
export interface CompleteDirectUploadInput {
disk?: string;
key: string;
uploadId: string;
parts: MultipartPart[];
}
export interface AbortDirectUploadInput {
disk?: string;
key: string;
uploadId: string;
}
export interface ProxyUploadInput {
disk?: string;
key: string;
contents: Uint8Array | Readable;
contentType?: string;
visibility?: 'public' | 'private';
}
/**
* Coordinates the two direct-S3 upload strategies over a {@link StorageManager}:
*
* - **proxy** — the client sends bytes to the app, which streams them to the disk with
* `put`/`putStream` (works on any disk). {@link proxyUpload} / {@link proxyUploadPart}.
* - **direct** — for multipart-capable disks (S3), the app hands the client presigned part URLs so
* the client uploads straight to S3, then assembles the parts. {@link initiateDirect} /
* {@link presignPart} / {@link completeDirect} / {@link abortDirect}.
*
* This is the framework-free core; the AdonisJS provider exposes it over HTTP routes and
* {@link MediaManager} delegates its `*DirectUpload` convenience methods here.
*/
export declare class UploadManager {
private readonly storage;
private readonly mode;
private readonly partSize;
private readonly presignTtlSeconds;
private readonly emitDiagnostics;
constructor(options: UploadManagerOptions);
/**
* Resolve the effective mode for a disk (`proxy`/`direct`), honouring the per-call override, the
* configured global default, and the disk's multipart capability. Throws when `direct` is forced
* on a disk that can't do multipart.
*/
resolveMode(input?: {
disk?: string;
mode?: UploadMode;
}): ResolvedUploadMode;
/** Begin a direct multipart upload and return a presigned URL per part for the client to PUT to. */
initiateDirect(input: InitiateDirectUploadInput): Promise<DirectUploadCreated>;
/** Issue a presigned URL for a single (e.g. retried) part of an in-flight direct upload. */
presignPart(input: PresignPartInput): Promise<{
url: string;
}>;
/** Assemble the uploaded parts into the final object, closing out the direct upload. */
completeDirect(input: CompleteDirectUploadInput): Promise<{
key: string;
disk: string;
}>;
/** Discard an in-flight direct upload and free its parts on S3. */
abortDirect(input: AbortDirectUploadInput): Promise<void>;
/**
* Proxy upload: stream the whole body through the app to the disk in a single write. Uses the
* disk's `putStream` for a `Readable` (no in-memory buffering) and falls back to `put` for bytes.
* Works on any disk — no multipart capability required.
*/
proxyUpload(input: ProxyUploadInput): Promise<{
key: string;
disk: string;
}>;
/**
* Proxy a single multipart part's bytes server-side (client PUTs the part to the app, the app
* forwards it to S3). Pairs with {@link initiateDirect}/{@link completeDirect} for a
* proxy-through-backend multipart flow on a multipart-capable disk.
*/
proxyUploadPart(input: {
disk?: string;
key: string;
uploadId: string;
partNumber: number;
body: Uint8Array;
}): Promise<MultipartPart>;
}
//# sourceMappingURL=upload_manager.d.ts.map