fix(core): handle partial listing data
This commit is contained in:
@@ -274,7 +274,7 @@ function parseEbayListings(
|
||||
);
|
||||
|
||||
// Filter to only elements that actually contain prices (not labels)
|
||||
const actualPrices: HTMLElement[] = [];
|
||||
const actualPrices: Element[] = [];
|
||||
for (const el of allPriceElements) {
|
||||
const text = el.textContent?.trim();
|
||||
if (text && EBAY_PRICE_TEXT_RE.test(text) && text.length < 50) {
|
||||
@@ -301,11 +301,10 @@ function parseEbayListings(
|
||||
|
||||
if (nonStrikethroughPrices.length > 0) {
|
||||
// Use the first non-strikethrough price (sale price)
|
||||
priceElement = nonStrikethroughPrices[0];
|
||||
priceElement = nonStrikethroughPrices[0] ?? null;
|
||||
} else {
|
||||
// Fallback: use the last price (likely the most current)
|
||||
const lastPrice = actualPrices[actualPrices.length - 1];
|
||||
priceElement = lastPrice;
|
||||
priceElement = actualPrices[actualPrices.length - 1] ?? null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ interface FacebookMarketplaceItem {
|
||||
__typename: "GroupCommerceProductItem";
|
||||
|
||||
// Listing content
|
||||
marketplace_listing_title: string;
|
||||
marketplace_listing_title?: string;
|
||||
redacted_description?: {
|
||||
text: string;
|
||||
};
|
||||
@@ -99,7 +99,7 @@ interface FacebookMarketplaceItem {
|
||||
listing_price?: {
|
||||
amount: string;
|
||||
currency: string;
|
||||
amount_with_offset: string;
|
||||
amount_with_offset?: string;
|
||||
};
|
||||
|
||||
// Location
|
||||
@@ -127,9 +127,9 @@ interface FacebookMarketplaceItem {
|
||||
|
||||
// Seller information
|
||||
marketplace_listing_seller?: {
|
||||
__typename: "User";
|
||||
id: string;
|
||||
name: string;
|
||||
__typename?: "User";
|
||||
id?: string;
|
||||
name?: string;
|
||||
profile_picture?: {
|
||||
uri: string;
|
||||
};
|
||||
@@ -1321,6 +1321,14 @@ export async function fetchFacebookItem(
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemResponseUrl.includes("unavailable_product=1")) {
|
||||
logExtractionMetrics(false, itemId);
|
||||
console.warn(
|
||||
`Item ${itemId} appears to be sold or removed from marketplace.`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const itemData = extractFacebookItemData(itemHtml);
|
||||
|
||||
if (classification.unavailable && !itemData) {
|
||||
|
||||
Reference in New Issue
Block a user