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

33 lines • 1.54 kB
/** Default page size for {@link MediaStore.list} when `limit` is omitted. */ export const DEFAULT_MEDIA_LIST_LIMIT = 50; /** Hard cap on {@link MediaStore.list} page size, so a caller can't request an unbounded scan. */ export const MAX_MEDIA_LIST_LIMIT = 200; /** Whether a record's tenant is one of `tenantIds` (`undefined`: no filter). */ export function tenantMatches(tenantIds, tenantId) { return tenantIds === undefined || tenantIds.includes(tenantId ?? null); } /** Encode a keyset into the opaque `nextCursor` string handed back to callers (URL-safe base64). */ export function encodeMediaCursor(cursor) { return Buffer.from(JSON.stringify(cursor), 'utf8').toString('base64url'); } /** Decode a `cursor` produced by {@link encodeMediaCursor}; returns null when malformed. */ export function decodeMediaCursor(cursor) { if (!cursor) return null; try { const parsed = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8')); if (typeof parsed.createdAt !== 'number' || typeof parsed.id !== 'string') return null; return { createdAt: parsed.createdAt, id: parsed.id }; } catch { return null; } } /** Clamp a requested page size to `[1, MAX_MEDIA_LIST_LIMIT]`, defaulting when omitted. */ export function clampMediaListLimit(limit) { if (limit === undefined || !Number.isFinite(limit)) return DEFAULT_MEDIA_LIST_LIMIT; return Math.max(1, Math.min(MAX_MEDIA_LIST_LIMIT, Math.floor(limit))); } //# sourceMappingURL=media_store.js.map