24 lines
968 B
TypeScript
24 lines
968 B
TypeScript
export function assetPreviewUrl(asset: { id: string }) {
|
|
return `/api/assets/${encodeURIComponent(asset.id)}/download?inline=1`;
|
|
}
|
|
|
|
// Binary reads stay on the application origin so browser fetch/canvas callers
|
|
// do not follow a private-OSS preview redirect and require bucket CORS access.
|
|
export function assetContentUrl(asset: { id: string }) {
|
|
return `/api/assets/${encodeURIComponent(asset.id)}/download`;
|
|
}
|
|
|
|
export function materialPreviewUrl(material: { id?: string; url: string }) {
|
|
return material.id ? assetPreviewUrl({ id: material.id }) : material.url;
|
|
}
|
|
|
|
export function materialContentUrl(material: { id?: string; url: string }) {
|
|
return material.id ? assetContentUrl({ id: material.id }) : material.url;
|
|
}
|
|
|
|
export function storedAssetPreviewUrl(url: string | undefined, assets: Array<{ id: string; url: string }>) {
|
|
if (!url) return "";
|
|
const asset = assets.find((item) => item.url === url);
|
|
return asset ? assetPreviewUrl(asset) : url;
|
|
}
|