fix: normalize MicroDAO logo URLs using helper function

This commit is contained in:
Apple
2025-12-01 06:23:54 -08:00
parent c68935d3a3
commit fbf17be668
3 changed files with 43 additions and 6 deletions

View File

@@ -0,0 +1,35 @@
/**
* Normalize asset URL for display
* Handles various URL formats from the backend:
* - /api/static/uploads/... - already correct
* - /assets/... - static assets, use as-is
* - /static/uploads/... - needs /api prefix
* - https://... - external URL, use as-is
*/
export function normalizeAssetUrl(url: string | null | undefined): string | null {
if (!url) return null;
// Already correct format
if (url.startsWith('/api/static')) {
return url;
}
// Static assets in public folder
if (url.startsWith('/assets/')) {
return url;
}
// External URLs
if (url.startsWith('http://') || url.startsWith('https://')) {
return url;
}
// Old format - needs /api prefix
if (url.startsWith('/static/')) {
return `/api${url}`;
}
// Unknown format - return as-is
return url;
}