@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
70 lines • 3.1 kB
TypeScript
/**
* Signed delivery URLs (`delivery.signing`) — the imgproxy/Thumbor model: the app signs the exact
* request (record, conversion, size, expiry) with a secret, and the delivery route serves only
* requests it signed. Nothing about the URL can be changed without breaking the signature, so a
* signed URL can ask for any width (the app chose it) and still not be turned into a key to other
* records or sizes — and an `<img>`, which cannot send an auth header, carries its authorization
* in the URL until it expires.
*/
export interface DeliverySigningConfig {
/** HMAC key — e.g. `env.get('APP_KEY')`. Rotating it invalidates every outstanding URL. */
secret: string;
/**
* How long a signed URL stays valid, in seconds. Default 3600. Expiries are rounded up to a
* multiple of this, so a page rendered twice within the window gets the same URLs and the
* browser cache keeps working — a URL is valid for between one and two windows.
*/
expiresIn?: number;
/**
* Refuse unsigned requests at the delivery route. Default `true`: with signing configured, the
* point is usually that nothing is reachable without a URL the app handed out.
*/
required?: boolean;
}
/** What a signature covers. */
export interface SignedDeliveryParams {
mediaId: string;
conversion?: string | undefined;
width?: number | undefined;
quality?: number | undefined;
/** Unix seconds. */
expires: number;
}
/** The query parameters of a delivery URL, as the route receives them. */
export interface DeliveryQuery {
conversion?: string | undefined;
w?: string | undefined;
q?: string | undefined;
exp?: string | undefined;
sig?: string | undefined;
}
export declare const DEFAULT_DELIVERY_SIGNING_TTL_SECONDS = 3600;
/** HMAC-SHA256 over the canonical form of the params, base64url. */
export declare function signDelivery(secret: string, params: SignedDeliveryParams): string;
/**
* Expiry for a URL signed now: `now + ttl`, rounded up to a multiple of `ttl` so the URL is stable
* for the rest of the window.
*/
export declare function deliveryExpiry(nowMs: number, ttlSeconds: number): number;
/**
* Check a request's signature. Throws {@link DeliverySignatureError} when it is invalid or expired.
* Returns `false` when the request carries no signature at all (the caller decides whether that is
* allowed), `true` when it is signed and valid.
*/
export declare function verifyDelivery(secret: string, request: {
mediaId: string;
conversion?: string | undefined;
width?: number | string | undefined;
quality?: number | string | undefined;
expires?: number | string | undefined;
signature?: string | undefined;
}, nowMs: number): boolean;
/** Build the query string of a delivery URL. */
export declare function deliveryQueryString(params: {
conversion?: string | undefined;
width?: number | undefined;
quality?: number | undefined;
expires?: number | undefined;
signature?: string | undefined;
}): string;
//# sourceMappingURL=delivery_signing.d.ts.map