@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
105 lines • 5.53 kB
TypeScript
import type { IncomingMessage } from 'node:http';
import { type Readable } from 'node:stream';
import type { DeliveryMode } from '../delivery.js';
import type { MediaLibrary } from '../media_library.js';
import type { MediaStore } from '../media_store.js';
import { type TenantAuthRequest, type VerifiedTenant, type VerifiedUser } from './auth.js';
/** The slice of an AdonisJS `HttpContext` the control plane uses (the test harness fakes it). */
export interface ControlPlaneContext {
params: Record<string, unknown>;
request: {
header(name: string): string | undefined | null;
qs(): Record<string, unknown>;
body?(): unknown;
/** The raw Node request: upload bodies are streamed from it. */
request: IncomingMessage;
};
response: {
status(code: number): unknown;
header(name: string, value: string): unknown;
send(body: unknown): unknown;
json(body: unknown): unknown;
stream(stream: Readable): unknown;
};
}
type Handler = (ctx: ControlPlaneContext) => Promise<unknown>;
/** The router methods the control plane needs (AdonisJS' router has them). */
export interface ControlPlaneRouter {
route(pattern: string, methods: string[], handler: Handler): unknown;
}
/** A person's own files (`controlPlane.accounts` in config/media.ts). */
export interface ControlPlaneAccountsOptions {
/** The collections a person's own token writes to. Make them `single: true` (one avatar). */
collections: readonly string[];
/** Verifies a person's access token. `null` (or a throw) refuses it. */
verifyUser: (token: string) => Promise<VerifiedUser | null> | VerifiedUser | null;
/** The owner type of account files on the control plane. Default `Account`. */
ownerType?: string;
/** The OIDC clients whose tokens may write. Default: any client. */
clients?: readonly string[];
/** The scope a person's token needs to write. Default `profile`. */
scope?: string;
/** Largest upload, in bytes. Default 5 MiB. */
maxBytes?: number;
}
export interface MediaControlPlaneOptions {
/** The library of one partition (`undefined`: the whole store, for account files). */
library: (partition?: string) => MediaLibrary | Promise<MediaLibrary>;
/** The store of one partition (only its records), for the cross-owner listing. */
store: (partition: string) => MediaStore | Promise<MediaStore>;
/** Verifies a tenant's token. */
verifyTenant: (request: TenantAuthRequest) => Promise<VerifiedTenant | null>;
/** `/_media`. */
prefix?: string;
/** Collections tenants may use. Default: every collection. */
collections?: readonly string[] | undefined;
/** Largest upload, in bytes. Default 100 MiB. */
maxBytes?: number;
/** This app's `delivery.mode`: `proxy` means tenants get bytes, never storage URLs. */
deliveryMode?: DeliveryMode | undefined;
accounts?: ControlPlaneAccountsOptions | undefined;
logger?: {
warn(message: string): void;
error?(message: string): void;
};
}
/**
* The media control plane's tenant API, under `<prefix>/v1` (default `/_media/v1`). Every request
* carries a bearer token: a tenant app's service token (the partition and capabilities come from
* it, never from the request) or, for the `accounts/me` writes, a person's own access token.
*
* - `GET /whoami` — the token's partition, capabilities and what it may use;
* - `GET /records` — one page of the app's records (`collection`, `ownerType`, `ownerId`, `cursor`, `limit`);
* - `GET /owners/:ownerType/:ownerId/records` — one owner's records (`collection`);
* - `POST /records` — add a file (body: the bytes; `x-media-attach`: what it is);
* - `GET /records/:id`, `PATCH /records/:id` (`{ name }`), `DELETE /records/:id`;
* - `POST /records/:id/conversions/:conversion` — generate a conversion now;
* - `GET /records/:id/file` — the bytes (`conversion`, `w`, `q`; `ETag`, `304`);
* - `GET /records/:id/url` — a storage URL, when this app does not deliver by proxy;
* - `GET /records/:id/image` — the responsive-image props;
* - `GET /accounts/:accountId/:collection[/file]` — a person's files (service token);
* - `PUT /accounts/me/:collection`, `DELETE /accounts/me/:collection` — the person's own token.
*/
export declare class MediaControlPlane {
#private;
readonly prefix: string;
constructor(options: MediaControlPlaneOptions);
register(router: ControlPlaneRouter): void;
whoami(ctx: ControlPlaneContext): Promise<unknown>;
listRecords(ctx: ControlPlaneContext): Promise<unknown>;
ownerRecords(ctx: ControlPlaneContext): Promise<unknown>;
addRecord(ctx: ControlPlaneContext): Promise<unknown>;
showRecord(ctx: ControlPlaneContext): Promise<unknown>;
renameRecord(ctx: ControlPlaneContext): Promise<unknown>;
deleteRecord(ctx: ControlPlaneContext): Promise<unknown>;
ensureConversion(ctx: ControlPlaneContext): Promise<unknown>;
recordFile(ctx: ControlPlaneContext): Promise<unknown>;
recordUrl(ctx: ControlPlaneContext): Promise<unknown>;
recordImage(ctx: ControlPlaneContext): Promise<unknown>;
replaceOwnFile(ctx: ControlPlaneContext): Promise<unknown>;
removeOwnFiles(ctx: ControlPlaneContext): Promise<unknown>;
accountRecords(ctx: ControlPlaneContext): Promise<unknown>;
accountFile(ctx: ControlPlaneContext): Promise<unknown>;
}
export {};
//# sourceMappingURL=control_plane.d.ts.map