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

32 lines • 1.3 kB
import { loadMediabunny } from './mediabunny_loader.js'; import { withSourceFile } from './source_file.js'; import { compactMeta } from './video.js'; /** * The built-in **metadata-only** {@link Transformer}: reads a media file's technical metadata — * duration, resolution, codecs, channel layout — and persists it as * `record.conversions['probe'].meta`, writing **no artifact at all**. The reference implementation * of the "derive metadata, not files" transformer shape; the model for a blurhash/thumbhash * placeholder transformer. * * ```ts * await media.library.transform(id, 'probe') * const record = await media.library.find(id) * record.conversions.probe?.meta // { durationSeconds: 41.6, width: 1920, ... } * ``` */ export class MetadataProbeTransformer { name; eager; engine; constructor(options = {}) { this.name = options.name ?? 'probe'; this.eager = options.eager ?? false; this.engine = options.engine; } async transform(context) { const engine = this.engine ?? (await loadMediabunny(this.name)).createProbeEngine(); const summary = await withSourceFile(context, ({ sourcePath }) => engine.probe(sourcePath)); return { meta: compactMeta({ ...summary }) }; } } //# sourceMappingURL=probe.js.map