@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
75 lines • 3.51 kB
TypeScript
import type { Disk } from '../types.js';
/**
* A configured disk: a lazy thunk the media provider calls at boot to build a {@link Disk}. Each
* factory imports its peer dependency (e.g. `@aws-sdk/client-s3`) inside the thunk, so the driver
* is only loaded when it is actually selected — keeping that package optional.
*/
export type DiskFactory = () => Promise<Disk>;
/** Static AWS credentials for the S3 disk. Omit to let the SDK's default provider chain resolve them. */
export interface S3Credentials {
accessKeyId: string;
secretAccessKey: string;
sessionToken?: string;
}
/** Options for the S3-backed disk. Mirrors the common `@aws-sdk/client-s3` `S3ClientConfig` knobs. */
export interface S3DiskConfig {
/** Target bucket (required). */
bucket: string;
/** AWS region, e.g. `us-east-1`. */
region?: string;
/**
* Static credentials. Omit to use the AWS SDK default provider chain (env vars, shared config,
* IAM role, etc.).
*/
credentials?: S3Credentials;
/** Custom endpoint for S3-compatible services (MinIO, R2, DigitalOcean Spaces, …). */
endpoint?: string;
/**
* Endpoint presigned URLs are signed against, when it differs from `endpoint`. Presigned URLs are
* consumed by the BROWSER (direct-upload part `PUT`s, signed `GET`s) and SigV4 bakes the host into
* the signature — so when `endpoint` is an internal FQDN the internet cannot resolve (MinIO on a
* private network), set the public one here. Server-side operations keep using `endpoint`.
*/
publicEndpoint?: string;
/** Use path-style addressing (`endpoint/bucket/key`) — required by most S3-compatible services. */
forcePathStyle?: boolean;
/** Prefix prepended to every key (e.g. `uploads`). */
keyPrefix?: string;
/** Base URL for stable public URLs (a CDN or the bucket website), used by `getUrl`. */
publicBaseUrl?: string;
/**
* Whether objects on this disk are readable without credentials. Declarative, and read only by
* `delivery.mode: 'auto'` (public ⇒ a plain URL, private ⇒ a signed one). Default `private`.
*/
visibility?: 'public' | 'private';
}
/**
* The disk factory namespace used in `config/media.ts`, parallel to `stores` and `processors`:
*
* ```ts
* import { defineConfig, disks } from '@adonis-agora/media'
*
* export default defineConfig({
* disk: 's3',
* disks: {
* s3: disks.s3({ bucket: 'my-bucket', region: 'us-east-1', publicBaseUrl: 'https://cdn.example.com' }),
* },
* })
* ```
*
* Each factory returns a {@link DiskFactory} — a lazy thunk. Calling it in the config file costs
* nothing; `@aws-sdk/client-s3` is only imported when the provider builds the selected disk at
* boot, keeping the AWS SDK an optional peer. (Presigning needs no SDK at all — it is hand-rolled
* SigV4, see `sigv4.ts`.)
*/
export declare const disks: {
/** S3 (or S3-compatible) disk — needs the optional `@aws-sdk/client-s3` peer. */
s3(config: S3DiskConfig): DiskFactory;
};
/**
* Build every disk named in `config.disks` into a concrete {@link Disk} map. The media provider
* calls this once at boot (each factory lazily loads its peer), then serves the resulting disks
* from a synchronous resolver, falling back to Drive for any name not defined here.
*/
export declare function resolveConfiguredDisks(factories: Record<string, DiskFactory> | undefined): Promise<Record<string, Disk>>;
//# sourceMappingURL=factory.d.ts.map