diff --git a/src/utils/productImage.ts b/src/utils/productImage.ts index 1722c30..d0a29c4 100644 --- a/src/utils/productImage.ts +++ b/src/utils/productImage.ts @@ -35,8 +35,17 @@ function storageRelativePath(value: string): string | null { function joinProjectUrl(relative: string): string { const path = relative.replace(/^\//, '') - const base = projectBase() - if (!base) return `/${path}` + let base = projectBase() + if (!base && typeof window !== 'undefined') { + base = `${window.location.origin}/server` + } + if (!base) { + return `/server/${path}` + } + base = base.replace(/\/$/, '') + if (path.startsWith('storage/') && !/\/(server|api)(\/|$)/i.test(base)) { + base = `${base}/server` + } let url = `${base}/${path}` if (typeof window !== 'undefined' && window.location.protocol === 'https:') { url = url.replace(/^http:\/\//i, 'https://') @@ -53,7 +62,7 @@ export function normalizePublicFileUrl(raw?: string | null): string | null { if (/^(data:|blob:)/i.test(trimmed)) return trimmed const storagePath = storageRelativePath(trimmed) - if (storagePath && projectBase()) { + if (storagePath) { return joinProjectUrl(storagePath) }