@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
96 lines • 4.5 kB
TypeScript
import { type ResolvedMediaTenancy } from '../agora/tenancy.js';
import type { MediaCollectionRegistry } from '../media_collection.js';
import type { MediaRecord } from '../media_record.js';
import type { MediaListPage, MediaOwnerPageOptions } from '../media_store.js';
import type { AccountExtension, AccountExtensionContext } from './contract.js';
/** One collection on the "My files" page, with the operations it offers (all on by default). */
export interface MediaAccountCollection {
/** The collection name (as in `config/media.ts` `collections`). */
name: string;
/** Tab label. Default: the collection name. */
label?: string;
/** Offer uploads into it. Default `true` (still needs the collection's `access.write`). */
upload?: boolean;
/** Offer renaming its files. Default `true` (needs `access.write`). */
rename?: boolean;
/** Offer deleting its files (confirmed, after re-authentication). Default `true` (needs `access.write`). */
delete?: boolean;
/** Offer downloads (short-lived signed URLs). Default `true` (needs `access.read`). */
download?: boolean;
}
/** `config/media.ts` → `accountConsole`: media's "My files" page in the authkit account console. */
export interface MediaAccountConsoleOptions {
/**
* The collections the page shows. Nothing is exposed until you list one. Each listed collection
* gets browse, upload, rename, delete and download, each allowed by that collection's own
* `access` rules (`read` for browse and download, `write` for the rest).
*/
collections: ReadonlyArray<string | MediaAccountCollection>;
/**
* Who owns "my" files. Default: the app user authkit mapped the account to (`subject`), else
* `{ type: 'User', id: account.id }`.
*/
owner?: (ctx: AccountExtensionContext) => {
type: string;
id: string;
} | Promise<{
type: string;
id: string;
}>;
/** Files per page. Default 20. */
pageSize?: number;
/** Lifetime of a download link, in seconds. Default 300. */
downloadTtlSeconds?: number;
/** Largest upload accepted, in bytes. Default 50 MiB. */
maxUploadBytes?: number;
/** Where the upload endpoint and its script are mounted. Default `/media/account`. */
path?: string;
/**
* This app's public https URL, when its pages are shown by an IdP running in another app
* (authkit-client `accountConsole.remote`): the upload script, the upload endpoint and download
* links then point here.
*/
publicUrl?: string;
}
/** The media manager slice the page reads and acts through. */
export interface MediaAccountManager {
readonly tenancy: ResolvedMediaTenancy;
readonly library: {
readonly collections: MediaCollectionRegistry;
find(id: string): Promise<MediaRecord | null>;
page(ownerType: string, ownerId: string, options?: MediaOwnerPageOptions): Promise<MediaListPage>;
rename(id: string, name: string): Promise<MediaRecord>;
delete(id: string): Promise<void>;
signedUrl(id: string, expiresIn: string | number, options?: {
contentDisposition?: string;
}): Promise<string>;
};
}
/** What {@link mediaAccountExtension} needs. */
export interface MediaAccountDeps {
media: () => Promise<MediaAccountManager>;
options: MediaAccountConsoleOptions;
/** HMAC secret for upload tickets. */
secret: string;
now?: () => number;
}
/** Defaults. */
export declare const ACCOUNT_DEFAULTS: {
readonly pageSize: 20;
readonly downloadTtlSeconds: 300;
readonly maxUploadBytes: number;
readonly path: '/media/account';
readonly ticketTtlMs: number;
};
/** The listed collections, normalized (duplicates dropped). */
export declare function accountCollections(options: MediaAccountConsoleOptions): MediaAccountCollection[];
/** The mount path of the upload endpoint (no trailing slash). */
export declare function accountPath(options: MediaAccountConsoleOptions): string;
/**
* Media's "My files" page for the authkit account console (`/account/files`): the signed-in
* user's files in the collections the app listed, with upload, rename, delete and download, each
* gated by that collection's own `access` rules. Every action re-checks ownership from the account
* (a file that is not theirs answers not found).
*/
export declare function mediaAccountExtension(deps: MediaAccountDeps): AccountExtension;
//# sourceMappingURL=extension.d.ts.map