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:
2026-08-25 20:49:53 +03:30
co-authored by Cursor
parent 29579f80d3
commit ff3a1cb00b
2 changed files with 40 additions and 8 deletions
@@ -57,22 +57,45 @@ function productFileId(product: Product): number {
return Number(product.file_id ?? (product.file as { id?: number } | undefined)?.id ?? 0)
}
function productHasDisplayImage(product: Product): boolean {
const file = product.file as { full_src?: string; url?: string; src?: string } | null | undefined
if (file && (file.full_src || file.url || file.src)) {
return true
}
return !!(product.img && /^https?:\/\//i.test(product.img))
}
/** استریم گاهی file خالی با همان file_id می‌فرستد — عکس خوب HTTP را پاک نکن. */
function mergeLiveProductList(incoming: Product[], current?: Product[]): Product[] {
if (!current?.length) return incoming
const currentById = new Map(current.map((item) => [item.id, item]))
return incoming.map((item) => {
const prev = currentById.get(item.id)
if (!prev || productFileId(prev) <= productFileId(item)) {
return item
if (!prev) return item
const prevId = productFileId(prev)
const nextId = productFileId(item)
if (!productHasDisplayImage(item) && productHasDisplayImage(prev)) {
return {
...item,
file: prev.file,
file_id: prev.file_id ?? (prev.file as { id?: number } | undefined)?.id ?? item.file_id,
img: prev.img,
}
}
return {
...item,
file: prev.file,
file_id: prev.file_id,
img: prev.img,
if (prevId > nextId) {
return {
...item,
file: prev.file,
file_id: prev.file_id,
img: prev.img,
}
}
return item
})
}