UNPKG

@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

60 lines • 2.8 kB
/** * 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 const disks = { /** S3 (or S3-compatible) disk — needs the optional `@aws-sdk/client-s3` peer. */ s3(config) { return async () => { const { S3Client } = await import('@aws-sdk/client-s3'); const { S3Disk } = await import('./s3.js'); const client = new S3Client({ ...(config.region !== undefined ? { region: config.region } : {}), ...(config.credentials !== undefined ? { credentials: config.credentials } : {}), ...(config.endpoint !== undefined ? { endpoint: config.endpoint } : {}), ...(config.forcePathStyle !== undefined ? { forcePathStyle: config.forcePathStyle } : {}), }); return new S3Disk({ client, bucket: config.bucket, ...(config.keyPrefix !== undefined ? { keyPrefix: config.keyPrefix } : {}), ...(config.publicBaseUrl !== undefined ? { publicBaseUrl: config.publicBaseUrl } : {}), ...(config.region !== undefined ? { region: config.region } : {}), ...(config.endpoint !== undefined ? { endpoint: config.endpoint } : {}), ...(config.publicEndpoint !== undefined ? { publicEndpoint: config.publicEndpoint } : {}), ...(config.forcePathStyle !== undefined ? { forcePathStyle: config.forcePathStyle } : {}), ...(config.visibility !== undefined ? { visibility: config.visibility } : {}), }); }; }, }; /** * 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 async function resolveConfiguredDisks(factories) { const built = {}; if (factories) { for (const [name, factory] of Object.entries(factories)) { built[name] = await factory(); } } return built; } //# sourceMappingURL=factory.js.map