23 lines
1.0 KiB
JavaScript
23 lines
1.0 KiB
JavaScript
// utils/media.util.js
|
|
//
|
|
// Resolves a displayable <img> src for an asset payload that may carry a
|
|
// short-lived stream_token (private/S3 — proxied through the backend) instead
|
|
// of a raw file_url. Private assets must never expose their real storage URL
|
|
// to the browser — see controllers/admin/assets.controller.js's redactS3Url
|
|
// pattern, mirrored for advertisements in controllers/*/advertisements.controller.js.
|
|
|
|
const API_BASE = (import.meta.env.VITE_API_URL ?? "http://localhost:3024").replace(/\/$/, "");
|
|
|
|
export function streamUrl(token) {
|
|
return token ? `${API_BASE}/client/media/stream/${token}` : null;
|
|
}
|
|
|
|
// asset: { stream_token?, file_url?, thumbnail_url? } — stream_token always
|
|
// wins when present (proxied); file_url/thumbnail_url are only ever populated
|
|
// here for public/chibisafe assets, which don't need proxying.
|
|
export function resolveAssetSrc(asset) {
|
|
if (!asset) return null;
|
|
if (asset.stream_token) return streamUrl(asset.stream_token);
|
|
return asset.thumbnail_url || asset.file_url || null;
|
|
}
|