fix: Correct ARC photos

This commit is contained in:
Brennan Wilkes (Text Groove) 2026-02-10 15:43:11 -08:00
parent 8da70b5d24
commit 2366d70d9c

View file

@ -87,7 +87,29 @@ function isInStock(p) {
return Boolean(p?.available_for_sale);
}
function arcItemToTracked(p, ctx) {
function arcNormalizeImg(raw) {
const s = String(raw || "").trim();
if (!s) return "";
// already public
if (/^https?:\/\/s\.barnetnetwork\.com\/img\/m\//i.test(s)) return s;
// site-relative -> public CDN
const noProto = s.replace(/^https?:\/\/[^/]+/i, "");
const rel = noProto.replace(/^\/+/, "");
// common case: "custom/all/BC398280.png" OR "bc_lrs/000046/0000466854.jpg"
if (/^(custom\/|bc_lrs\/)/i.test(rel)) {
return `https://s.barnetnetwork.com/img/m/${rel}`;
}
// fallback: if it's any path, still try the CDN
if (rel && !/^data:/i.test(rel)) return `https://s.barnetnetwork.com/img/m/${rel}`;
return "";
}
function arcItemToTracked(p, ctx) {
if (!p) return null;
if (!isInStock(p)) return null;
@ -104,11 +126,11 @@ function arcItemToTracked(p, ctx) {
const taggedSku = cspc ? cspc : Number.isFinite(id) ? `id:${id}` : "";
const sku = normalizeSkuKey(taggedSku, { storeLabel: ctx?.store?.name, url }) || taggedSku || "";
const imgRaw = p.image || p.image_url || p.img || "";
const img = imgRaw ? normAbsUrl(imgRaw, `https://${ctx.store.host}/`) : "";
const img = arcNormalizeImg(p.image || p.image_url || p.img || "");
return { name, price, url, sku, img };
}
}
function parseCategoryParamsFromStartUrl(startUrl) {
try {