fix: tighten ebay result parsing

This commit is contained in:
2026-04-23 05:13:40 -04:00
parent 0a0723a560
commit 08d59ab497
2 changed files with 107 additions and 4 deletions

View File

@@ -43,7 +43,7 @@ const EBAY_PRICE_TEXT_RE = /^(?:\s*(?:CA|C)\s*\$|\s*[$£€¥])/u;
function canonicalizeEbayItemUrl(url: string): string {
try {
const parsed = new URL(url, "https://www.ebay.ca");
const match = parsed.pathname.match(/\/itm\/[^/?#]+/);
const match = parsed.pathname.match(/\/itm\/(?:[^/?#]+\/)?\d+/);
return match ? `${parsed.origin}${match[0]}` : `${parsed.origin}${parsed.pathname}`;
} catch {
return url;
@@ -267,8 +267,7 @@ function parseEbayListings(
if (
text &&
EBAY_PRICE_TEXT_RE.test(text) &&
text.length < 50 &&
!/\d{4}/.test(text)
text.length < 50
) {
actualPrices.push(el);
}
@@ -512,7 +511,7 @@ export default async function fetchEbayItems(
// Filter by price range (additional safety check)
const filteredListings = listings.filter((listing) => {
const cents = listing.listingPrice?.cents;
return cents && cents >= minPrice && cents <= maxPrice;
return typeof cents === "number" && cents >= minPrice && cents <= maxPrice;
});
console.log(`Parsed ${filteredListings.length} eBay listings.`);