fix: tighten ebay result parsing
This commit is contained in:
@@ -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.`);
|
||||
|
||||
Reference in New Issue
Block a user