@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
73 lines • 3.81 kB
TypeScript
import { MediaManager } from './media_manager.js';
import { type ImagePlaceholder } from './transformers/placeholder.js';
/**
* Store a single file for an owner and return stable public URLs. This is a thin, generic seam over
* {@link MediaManager} for callers (e.g. another Agora package storing an avatar) that only need to
* "replace this owner's one file and give me a URL", without touching the fuller library surface.
*
* Single-slot replacement is a property of the collection: the `collection` named here must be
* configured `single: true` in the app's `config/media.ts`. It is NOT an attach flag.
*/
export interface StoreSingleFileInput {
ownerType: string;
ownerId: string;
/** Must be configured `single: true` in the app's media config. */
collection: string;
fileName: string;
mimeType: string;
contents: Buffer;
}
export interface StoredSingleFile {
/** Public URL of the stored original. */
url: string;
/** Public URL of the `thumb` conversion, or `null` when that conversion isn't configured. */
thumbUrl: string | null;
/** Id of the stored media record — keep it to look the record up later without the owner. */
id: string;
/**
* The blur-up placeholder from a `transformers.placeholder()` on the collection
* (`{ dataUrl, width, height, color }`), or `null` when none is configured or it was skipped.
* Persist it next to the URL to paint a preview without a media lookup at render time.
*/
placeholder: ImagePlaceholder | null;
}
export interface RemoveSingleFileInput {
ownerType: string;
ownerId: string;
collection: string;
}
/**
* Core of {@link storeSingleFile} driven by an explicit {@link MediaManager}, so tests can exercise
* it with an in-memory manager without booting an app. Attaches the file to the owner's collection
* (single-file replacement comes from the collection config) and resolves the original URL plus,
* best-effort, a `thumb` conversion URL.
*/
export declare function storeSingleFileWith(manager: MediaManager, input: StoreSingleFileInput): Promise<StoredSingleFile>;
/**
* Core of {@link removeSingleFile} driven by an explicit {@link MediaManager}. Empties the owner's
* collection by deleting every record it holds (a single-file collection holds at most one).
*/
export declare function removeSingleFileWith(manager: MediaManager, input: RemoveSingleFileInput): Promise<void>;
/**
* Store a single file for an owner via the app-bound {@link MediaManager}. Resolves the manager from
* the container, then delegates to {@link storeSingleFileWith}. The `collection` must be configured
* `single: true` in `config/media.ts` for prior files to be replaced.
*
* The container is read from the provider-captured booted app ({@link getBootedApp}) rather than
* `@adonisjs/core/services/app` — see `./services/booted_app.js` for why that import is unreliable
* under a duplicated `@adonisjs/core` tree (pnpm dual-package hazard).
*/
export declare function storeSingleFile(input: StoreSingleFileInput): Promise<StoredSingleFile>;
/**
* Remove the owner's file in a collection via the app-bound {@link MediaManager}. Resolves the
* manager from the container, then delegates to {@link removeSingleFileWith}.
*/
export declare function removeSingleFile(input: RemoveSingleFileInput): Promise<void>;
/**
* Whether the single-file store is usable — i.e. the {@link MediaManager} is bound in the app
* container. Callers use this to feature-detect media before routing a store through it.
*/
export declare function isSingleFileStoreAvailable(): Promise<boolean>;
export type { ImagePlaceholder } from './transformers/placeholder.js';
export { placeholderOf } from './transformers/placeholder.js';
//# sourceMappingURL=single_file_store.d.ts.map