@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
94 lines • 3.81 kB
TypeScript
import type { Readable } from 'node:stream';
import type { ConversionPreset, ImageProcessor } from './image_processor.js';
import type { StorageManager } from './storage_manager.js';
import type { SignedUrlOptions } from './types.js';
export interface AttachmentVariant {
disk: string;
path: string;
size: number;
mimeType: string;
}
/** Plain, JSON-serializable shape stored in a model column. */
export interface AttachmentData {
name: string;
disk: string;
path: string;
size: number;
mimeType: string;
variants: Record<string, AttachmentVariant>;
meta: Record<string, unknown>;
}
/**
* A file attached to a model as a column value (adonis-attachment style). Pure value
* object — it carries disk + path + variant metadata and serializes to JSON. URL
* resolution and deletion go through {@link AttachmentManager} (which holds the disks).
*/
export declare class Attachment {
readonly name: string;
readonly disk: string;
readonly path: string;
readonly size: number;
readonly mimeType: string;
readonly variants: Record<string, AttachmentVariant>;
readonly meta: Record<string, unknown>;
constructor(data: AttachmentData);
toJSON(): AttachmentData;
/** Rebuild from a stored column value; returns null for null/undefined. */
static fromJSON(json: AttachmentData | null | undefined): Attachment | null;
}
export interface CreateAttachmentInput {
fileName: string;
mimeType: string;
contents: Buffer | Readable;
size?: number;
}
export interface CreateAttachmentOptions {
disk?: string;
/** Key prefix on the disk. Default `attachments`. */
keyPrefix?: string;
/** Image variants to generate eagerly (needs an ImageProcessor). */
variants?: ConversionPreset[];
/** Display name override (defaults to the file name). */
name?: string;
meta?: Record<string, unknown>;
}
/** Options for {@link AttachmentManager.signedUrl}: the disk's response headers, plus a variant to sign instead of the original. */
export interface AttachmentSignedUrlOptions extends Omit<SignedUrlOptions, 'expiresIn'> {
/** Sign this named variant instead of the original. */
variant?: string;
}
export interface AttachmentManagerOptions {
storage: StorageManager;
imageProcessor?: ImageProcessor;
keyPrefix?: string;
idGenerator?: () => string;
/** Emit `agora:media:attachment.*` diagnostics events (default true). */
emitDiagnostics?: boolean;
}
/**
* Creates and resolves {@link Attachment}s — the adonis-attachment-style API.
* `createFromFile` uploads the bytes (and any variants) and returns a value object
* you assign to a model column.
*/
export declare class AttachmentManager {
#private;
private readonly storage;
private readonly imageProcessor;
private readonly keyPrefix;
private readonly newId;
private readonly emitDiagnostics;
constructor(options: AttachmentManagerOptions);
createFromFile(input: CreateAttachmentInput, options?: CreateAttachmentOptions): Promise<Attachment>;
/** Public URL for the attachment, or a named variant. */
url(attachment: Attachment, variant?: string): Promise<string>;
/**
* Signed, expiring URL (presign-capable disks). Everything in `options` except `variant` is a
* response header baked into the URL, applying to whoever follows the link rather than to this
* call: `contentDisposition` is what forces a download with a chosen file name.
*/
signedUrl(attachment: Attachment, expiresIn: string | number, options?: AttachmentSignedUrlOptions): Promise<string>;
/** Remove the attachment and all its variants from storage. */
delete(attachment: Attachment): Promise<void>;
private resolve;
}
//# sourceMappingURL=attachment.d.ts.map