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

30 lines • 1.3 kB
import { DriveNotConfiguredError, DriveNotReadyError } from '../errors.js'; /** * Build the {@link DiskResolver} the media manager runs on: locally-configured disks first, then * `@adonisjs/drive`. * * The Drive manager is read **lazily, at the first disk resolution that actually needs it** — never * when the resolver is built — and memoized once found, so it is still resolved exactly once. This * is what makes the resolver safe to construct during `register()`, long before Drive has booted. * An app whose disks all come from `config.disks` never touches Drive at all. */ export function createDriveBackedResolver(options) { const { driveService, configuredDisks, defaultDisk, driveAvailable = true } = options; let drive; return (name) => { const key = name ?? defaultDisk; const configured = configuredDisks[key]; if (configured) return configured; if (drive === undefined) { if (!driveAvailable) throw new DriveNotConfiguredError(key); const resolved = driveService.default; if (resolved === undefined) throw new DriveNotReadyError(key); drive = resolved; } return drive.use(name); }; } //# sourceMappingURL=drive.js.map