@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
42 lines • 1.99 kB
JavaScript
/**
* Host-supplied context about a disk object, shown in the console's preview.
*
* Ported from the NestJS sibling console's `server/object-insights.ts`. The console can describe a
* file only as storage sees it: key, size, content type, last modified. Everything that makes the
* file *mean* something lives in the host — which work order this scan belongs to, which knowledge
* base indexed it. This is the seam for handing that back: the host registers a provider (via
* `config/media_dashboard.ts`'s `objectInsights`), the console asks it when an object is previewed
* and renders whatever comes back.
*
* **Data, not components** — same reason as the NestJS side: the console ships as a prebuilt SPA
* bundle, so a host cannot inject React into it. A provider returns a small structured value the
* console knows how to render (facts, links, a note).
*/
/** Schemes an {@link ObjectInsightLink} may point at. Anything else is dropped, not rendered. */
const SAFE_LINK_SCHEMES = new Set(['http:', 'https:']);
/**
* Drop links the console must not render. A relative href (`/ctrl/...`) always addresses the host's
* own app and is kept; an absolute one is kept only if it is http(s) (refuses `javascript:`/`data:`).
*/
export function sanitizeInsight(insight) {
if (insight.links === undefined)
return insight;
const links = insight.links.filter((link) => {
if (link.href.startsWith('/')) {
// `//evil.com` is protocol-relative — an absolute URL wearing a relative one's clothes.
return !link.href.startsWith('//');
}
try {
return SAFE_LINK_SCHEMES.has(new URL(link.href).protocol);
}
catch {
return false;
}
});
return { ...insight, links };
}
/** `{ insights: [] }` — what the console renders when no providers are registered. */
export function emptyInsights() {
return { insights: [] };
}
//# sourceMappingURL=object_insights.js.map