@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
79 lines • 3.21 kB
TypeScript
import { Readable } from 'node:stream';
import type { MediaRecord } from '../media_record.js';
import { type MediaTenantClient } from './tenant_client.js';
/** What reading a person's file answered. */
export type AccountFileRead = {
kind: 'file';
stream: Readable;
contentType: string;
size?: number | undefined;
etag?: string | undefined;
} | {
kind: 'not-modified';
etag?: string | undefined;
} | {
kind: 'not-found';
};
/** The response slice {@link TenantAccounts.serve} writes to (an AdonisJS `HttpContext`). */
export interface AccountServeContext {
request: {
header(name: string): string | undefined | null;
};
response: {
status(code: number): unknown;
header(name: string, value: string): unknown;
send(body: unknown): unknown;
stream(stream: Readable): unknown;
};
}
/**
* A person's own files on the media control plane (`controlPlane.accounts` there), shared by every
* app: an avatar uploaded in one app shows in all of them.
*
* - reading uses this app's service token (`media:read`);
* - writing and removing use the person's own access token: the control plane writes to the token's
* `sub`, so no app can change another person's file.
*
* ```ts
* // a controller: the person's avatar, served by this app
* return media.accounts.serve(ctx, params.id, 'avatar', { conversion: 'md' })
*
* // the person changes it (their session's access token)
* await media.accounts.replace(session.accessToken, 'avatar', { contents, mimeType })
* ```
*/
export declare class TenantAccounts {
private readonly client;
constructor(client: MediaTenantClient);
/** The person's records in `collection` (one for a `single` collection). */
records(accountId: string, collection: string): Promise<MediaRecord[]>;
/** The bytes of the person's file (a conversion of it), with `If-None-Match` passed on. */
read(accountId: string, collection: string, options?: {
conversion?: string;
width?: number;
ifNoneMatch?: string;
}): Promise<AccountFileRead>;
/**
* Answer a request with the person's file: `200` with the bytes, `304` when the browser's copy is
* current, `404` when there is none. Cached privately for a minute by default.
*/
serve(ctx: AccountServeContext, accountId: string, collection: string, options?: {
conversion?: string;
width?: number;
cacheControl?: string;
}): Promise<unknown>;
/**
* Replace the person's file in `collection` with `contents`, as the owner of `accessToken`
* (their own access token, never this app's). Refused content answers `422` with the media error
* code (`E_MEDIA_MIME_NOT_ALLOWED`, `E_MEDIA_CONTENT_TYPE_MISMATCH`, …).
*/
replace(accessToken: string, collection: string, input: {
contents: Buffer | Readable;
mimeType: string;
fileName?: string;
size?: number;
}): Promise<MediaRecord>;
/** Remove the person's files in `collection`, as the owner of `accessToken`. Idempotent. */
remove(accessToken: string, collection: string): Promise<void>;
}
//# sourceMappingURL=tenant_accounts.d.ts.map