mirror of
https://github.com/samsonjs/spirit-tracker.git
synced 2026-03-25 09:25:51 +00:00
fix: Correct ARC photos
This commit is contained in:
parent
8da70b5d24
commit
2366d70d9c
1 changed files with 44 additions and 22 deletions
|
|
@ -87,6 +87,28 @@ function isInStock(p) {
|
|||
return Boolean(p?.available_for_sale);
|
||||
}
|
||||
|
||||
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,12 +126,12 @@ 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 {
|
||||
const u = new URL(startUrl);
|
||||
|
|
|
|||
Loading…
Reference in a new issue