fix(products): absolutize image URLs and preserve them on SSE merge
Relative full_src now uses node_server, and empty live-list file payloads no longer wipe catalog images. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import mokaabImg from '@/assets/img/mokaabImg.svg'
|
||||
import sekkeImg from '@/assets/img/sekkeImg.svg'
|
||||
import parsianImg from '@/assets/img/parsianImg.svg'
|
||||
import venusImg from '@/assets/img/venousImg.svg'
|
||||
import { getConfigApp } from '@/utils/config'
|
||||
|
||||
export type ProductImageSource = {
|
||||
file?: { id?: number | null; src?: string | null; full_src?: string | null; url?: string | null } | null
|
||||
@@ -18,6 +19,14 @@ function isUsableImageSrc(src?: string | null): boolean {
|
||||
return value !== '' && value !== 'null' && value !== 'undefined'
|
||||
}
|
||||
|
||||
function absolutizeImageUrl(url: string): string {
|
||||
if (/^https?:\/\//i.test(url)) return url
|
||||
const base = String(getConfigApp('node_server') || '').replace(/\/$/, '')
|
||||
const path = url.replace(/^\//, '')
|
||||
if (!base) return url.startsWith('/') ? url : `/${url}`
|
||||
return `${base}/${path}`
|
||||
}
|
||||
|
||||
export function getProductFallbackImage(product?: ProductImageSource): string {
|
||||
const type = (product?.group_type ?? '').trim()
|
||||
if (!type) return defaultImg
|
||||
@@ -47,7 +56,7 @@ export function getProductFallbackImage(product?: ProductImageSource): string {
|
||||
export function resolveProductImageSrc(product?: ProductImageSource): string {
|
||||
const remoteSrc = product?.file?.full_src || product?.file?.url || product?.file?.src
|
||||
if (isUsableImageSrc(remoteSrc)) {
|
||||
const url = remoteSrc!.trim()
|
||||
const url = absolutizeImageUrl(remoteSrc!.trim())
|
||||
const version = product?.file_id ?? product?.file?.id
|
||||
if (version != null && version !== '' && Number(version) > 0 && /^https?:\/\//i.test(url) && !/[?&]v=/.test(url)) {
|
||||
return `${url}${url.includes('?') ? '&' : '?'}v=${encodeURIComponent(String(version))}`
|
||||
|
||||
Reference in New Issue
Block a user