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