@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
162 lines • 9.79 kB
TypeScript
import type { HttpContext } from '@adonisjs/core/http';
import type { FederatedConsoleApp } from '../federation/console.js';
import type { AccessDeniedOption as GenericAccessDeniedOption, AccessDeniedRenderer as GenericAccessDeniedRenderer } from './access_denied_page.js';
import type { ConsoleAuthorize } from './console_authorize.js';
import type { ConsoleViewer, SignOutOption, ViewerHook } from './console_shell.js';
import type { ObjectInsightProvider } from './object_insights.js';
import type { ObjectUrlStrategy } from './object_urls.js';
/**
* The function form of {@link MediaDashboardConfig.accessDenied}: render (or answer) a refused
* page navigation yourself. Receives the refusal ({@link AccessDeniedInfo}) and the AdonisJS
* {@link HttpContext}. Return an HTML string to have it served; answer the request yourself (a
* redirect, most commonly) and return nothing to make the provider stand down; return nothing
* WITHOUT answering and the built-in page is served.
*/
export type AccessDeniedRenderer = GenericAccessDeniedRenderer<HttpContext>;
/** `accessDenied` in either form — an options object for the built-in page, or a renderer. */
export type AccessDeniedOption = GenericAccessDeniedOption<HttpContext>;
/** A minimal middleware handler shape (host auth guard) applied to the console routes. */
export type DashboardMiddleware = (ctx: HttpContext, next: () => Promise<void>) => unknown;
/**
* Configuration for the `@adonis-agora/media` dashboard, read by `dashboard_provider.ts` from
* `config/media_dashboard.ts` (config key `media_dashboard`).
*
* The console is a read-only browser by default (`actions: false`); flip `actions` on — and gate the
* routes with your own `middleware` (an auth guard) — to enable copy/move/delete. Storage, uploads and
* everything else come from the already-configured `@adonis-agora/media` manager; this config only
* places the SPA + JSON API and picks which disks are browsable.
*/
export interface MediaDashboardConfig {
/** Mount the dashboard at all. Default `true`. Set `false` to register the provider (so its config
* type stays available) without actually exposing any route — e.g. per-environment. */
enabled?: boolean;
/** Where the SPA is mounted. Default `/media/dashboard`. */
basePath?: string;
/** Where the JSON API is mounted. Default `<basePath>/api`. */
apiBasePath?: string;
/** Enable mutating actions (copy/move/delete). Default `false`. */
actions?: boolean;
/**
* Disk names the console may browse/act on. When omitted, the provider derives them from the media
* config (`disks` keys plus the default disk).
*/
disks?: string[];
/** Prefix of the core direct-S3 upload routes, matched to `media.uploads.routes.prefix`. Default `/media/uploads`. */
uploadsPrefix?: string;
/** Prefix of the core TUS routes, matched to `media.uploads.resumable.routes.prefix`. Default `/media/uploads/tus`. */
tusPrefix?: string;
/** Host middleware (auth) applied to the whole console — SPA and API. */
middleware?: DashboardMiddleware | DashboardMiddleware[];
/**
* Who may open the console (SPA + API). Same contract as every other `@adonis-agora` console —
* see {@link ConsoleAuthorize}: an inline function, a `ConsoleAuthorizer` class (built through
* the container, so `@inject()` works), or a lazy import of one.
*
* Answer `true` / `{ allowed: true }` to allow; `false` / `{ allowed: false }` for `403`;
* `{ allowed: false, reason: 'unauthenticated' }` for `401`; `{ redirectTo: '/login' }` to send
* a page navigation there (API calls get `401`). A check that throws is a `403`. Runs before
* `middleware` (both must pass). Sign-in is your app's own: the console has no login. API refusals answer
* `{ error: 'forbidden' }` / `{ error: 'unauthenticated' }` JSON (plus `redirectTo` for a
* redirect); page navigations get the {@link accessDenied} page with the same status. For machine
* access, use `authorizeByToken({ token })`.
*
* Omitted: the console is open outside production and answers `403` to every page and API
* request in production, with a warning at boot. Set `authorize: () => true` to keep it open in
* production when `middleware` already guards it.
*/
authorize?: ConsoleAuthorize;
/**
* What a BROWSER sees when `authorize` refuses a page navigation — the SPA shell or its assets.
* API requests are unaffected: they keep getting `{ error: 'forbidden' }` (`403`) or
* `{ error: 'unauthenticated' }` (`401`) JSON. Omit it for the built-in page — a dark card in the
* console's own visual language with the same status as the API, a
* sentence explaining the refusal and a "Back to app" link. Pass an
* object to tweak that page (`brand`, `title`, `message`, `homeHref`, `accent`, …), or a function
* to render/answer it yourself — see {@link AccessDeniedRenderer}. A redirect written by
* `authorize` still wins: the provider never overwrites a `location` header.
*/
accessDenied?: AccessDeniedOption;
/**
* Host-supplied context about a disk object, rendered in the console's preview — see
* {@link ObjectInsightProvider}. The console can only describe a file as storage sees it; this is
* how it learns what the file *means* to your app. Omit for no annotation (the default).
*/
objectInsights?: ObjectInsightProvider[];
/**
* Where the `url` the console reports for an object's bytes points — the "Open ↗" link and the
* `src` of the image/video/audio previews. `'auto'` signs a URL straight to the object store;
* `'proxy'` routes it through this server's own `<apiBase>/object/raw`, for a deployment whose
* browsers cannot reach the store at all (private bucket on an internal network, no CORS grant).
* See {@link ObjectUrlStrategy}.
*
* Set `'proxy'` whenever the store is not internet-reachable — with `'auto'` the console mints a
* URL signed for the INTERNAL endpoint, which resolves nowhere in a browser.
*
* When unset, the console follows the core media config: `delivery.mode: 'proxy'` in
* `config/media.ts` implies `'proxy'` here (a host already streaming every read through the app
* has declared its store unreachable from a browser); anything else keeps `'auto'`. An explicit
* value always wins.
*/
objectUrls?: ObjectUrlStrategy;
/**
* Who the console's sidebar footer shows as signed in. Omit it to read `ctx.auth.user`
* structurally (`fullName`/`name`/`email`, first of `role`/`roles`) when the request is already
* authenticated; return `null` for no user row. A throw is treated as `null`.
*/
viewer?: ViewerHook;
/**
* The footer's "Sign out": a POST action path (`'/logout'`, sent with the CSRF token), `{ href }`
* for a plain link, or `false` for none. Omit it to use the sign-out an account console (authkit)
* announces on the `agora.consoles` registry, when there is one. Same-origin paths only.
*/
signOut?: SignOutOption;
/**
* Other apps this console also shows (the federated console), by a key that becomes their
* `?app=` in the console's URL. Each keeps its own tables, disks and credentials: the console
* reads that app's records and upload sessions from its tables and asks the app itself, over
* Redis, to list its disks, sign URLs and run the actions (that app sets `consoleCommands` in its
* `config/media.ts`).
*
* ```ts
* apps: {
* 'entre-textos': {
* label: 'Entre Textos',
* store: stores.lucid({ connection: 'pg', schema: 'entretextos' }),
* uploadSessions: uploadSessions.lucid({ connection: 'pg', schema: 'entretextos' }),
* controlPlane: { connection: 'main', prefix: 'entretextos' },
* origin: 'https://entretextos.example.com',
* },
* }
* ```
*
* Keys are 1–64 characters of `[A-Za-z0-9_.-]`. An `authorize` that grants `apps` as a list hides
* the apps it does not name. Uploading from the console stays this app's own. Organization
* grants (`tenants`) only apply to this app: a viewer granted another app sees all of its media.
* Each entry is checked at boot (`controlPlane`, `timeoutMs`, `origin`).
*/
apps?: Record<string, FederatedConsoleApp | ControlPlaneConsoleApp>;
/** The name of THIS app in the app selector (shown once `apps` is set). Defaults to `This app`. */
appLabel?: string;
}
/**
* A tenant app of this media control plane (`topology: 'control-plane'` in `config/media.ts`), by
* its partition: its media lives here, so the console reads it from this app's own tables and disks
* (only that app's records and files) and runs its actions here.
*
* ```ts
* apps: { 'entre-textos': { mode: 'control-plane', label: 'Entre Textos' } }
* ```
*/
export interface ControlPlaneConsoleApp {
mode: 'control-plane';
/** The name in the selector. Defaults to the key. */
label?: string;
/** Whether this console runs actions on that app's media. Default: the console's own `actions`. */
actions?: boolean;
}
/** Whether an `apps` entry is a tenant app of this control plane. */
export declare function isControlPlaneConsoleApp(entry: FederatedConsoleApp | ControlPlaneConsoleApp | undefined): entry is ControlPlaneConsoleApp;
export type { ConsoleViewer, FederatedConsoleApp, SignOutOption, ViewerHook };
/** Identity helper for authoring a typed `config/media_dashboard.ts`. */
export declare function defineConfig(config?: MediaDashboardConfig): MediaDashboardConfig;
//# sourceMappingURL=define_config.d.ts.map