@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
67 lines • 3.95 kB
TypeScript
/**
* HLS playlist (`.m3u8`) reference rewriting — the read-side half of the HLS transformer.
*
* Playlists are STORED with references relative to the package's storage layout (that is what the
* muxer emits, and it keeps the stored artifacts location-agnostic). At serve time those
* references must become URLs the player can actually fetch — the app's authenticated proxy
* routes, presigned object URLs, a CDN — and only the app knows which. This module does the part
* that is the same everywhere: find every reference in a playlist, classify it, and let a
* callback decide the URL. See {@link HlsDeliveryHandler} for the assembled read path.
*/
/** Content type playlists are served with (RFC 8216's `application/vnd.apple.mpegurl`). */
export declare const HLS_PLAYLIST_CONTENT_TYPE = "application/vnd.apple.mpegurl";
/** Content type for MPEG-TS segments. */
export declare const HLS_SEGMENT_CONTENT_TYPE = "video/mp2t";
/** One URI reference found in a playlist, handed to the {@link HlsUriRewriter}. */
export interface HlsUriRef {
/** The reference exactly as it appears in the playlist (may carry a query string). */
uri: string;
/**
* `'playlist'` for `.m3u8` references (variant streams in a master playlist, audio/subtitle
* renditions via `#EXT-X-MEDIA`), `'media'` for everything else (segments, `#EXT-X-MAP` init
* sections, keys). Classified by extension, ignoring any query/fragment.
*/
kind: 'playlist' | 'media';
/**
* The tag whose `URI="…"` attribute holds this reference (`'EXT-X-MEDIA'`, `'EXT-X-MAP'`,
* `'EXT-X-I-FRAME-STREAM-INF'`, …), or `undefined` for a plain URI line.
*/
tag?: string;
}
/**
* Maps one playlist reference to the URI that should replace it. Return the input unchanged to
* keep a reference as-is. May be async — building the replacement routinely involves presigning.
*/
export type HlsUriRewriter = (ref: HlsUriRef) => string | Promise<string>;
/**
* Rewrite every **relative** URI reference in an HLS playlist through `rewrite`, covering all the
* places RFC 8216 puts one:
*
* - plain URI lines (segments in a media playlist, variant playlists in a master playlist),
* - `URI="…"` attributes on tags (`#EXT-X-MEDIA` audio/subtitle renditions, `#EXT-X-MAP` init
* sections, `#EXT-X-I-FRAME-STREAM-INF`, `#EXT-X-KEY`, …).
*
* Untouched, by design:
* - **absolute** references (`https://…`, protocol-relative `//…`, root-relative `/…`) — they no
* longer describe the storage layout, so rewriting them is not this function's business;
* - comments and every other tag/line, byte for byte (line endings included).
*/
export declare function rewriteHlsPlaylist(content: string, rewrite: HlsUriRewriter): Promise<string>;
/**
* Whether a playlist reference is relative to the playlist's own location — the only kind that
* describes the storage layout and therefore the only kind {@link rewriteHlsPlaylist} rewrites.
* Anything carrying a scheme (`https:`, `data:`), protocol-relative (`//cdn/…`) or root-relative
* (`/api/…`) is already an address, not a layout detail.
*/
export declare function isRelativeUri(uri: string): boolean;
/** Classify a reference by extension (query/fragment ignored): `.m3u8` ⇒ playlist, else media. */
export declare function classifyUri(uri: string): 'playlist' | 'media';
/**
* Resolve a reference found in playlist `fromFile` (both package-relative) to the package-relative
* path it points at, collapsing `.`/`..` segments. Returns `null` when the reference escapes the
* package root — the caller treats that as "not one of ours" and leaves it alone.
*/
export declare function resolvePackagePath(fromFile: string, uri: string): string | null;
/** Content type for one artifact of an HLS package, by extension. */
export declare function hlsArtifactContentType(file: string): string | undefined;
//# sourceMappingURL=playlist.d.ts.map