feat(facebook): parse additional listing details like status, images, and seller info
Enhance Facebook scraping to extract listing status (ACTIVE/SOLD/PENDING/HIDDEN), primary image/video URLs, seller name/ID, category ID, and delivery options, improving response completeness.
This commit is contained in:
@@ -83,6 +83,15 @@ type ListingDetails = {
|
||||
endDate?: string;
|
||||
numberOfViews?: number;
|
||||
address?: string | null;
|
||||
// Facebook-specific fields
|
||||
imageUrl?: string;
|
||||
videoUrl?: string;
|
||||
seller?: {
|
||||
name?: string;
|
||||
id?: string;
|
||||
};
|
||||
categoryId?: string;
|
||||
deliveryTypes?: string[];
|
||||
};
|
||||
|
||||
// ----------------------------- Utilities -----------------------------
|
||||
@@ -437,11 +446,33 @@ function parseFacebookAds(ads: FacebookAdNode[]): ListingDetails[] {
|
||||
listing.location?.reverse_geocode?.city_page?.display_name;
|
||||
const address = cityName || null;
|
||||
|
||||
// Determine listing status from Facebook flags
|
||||
let listingStatus: string | undefined = undefined;
|
||||
if (listing.is_sold) {
|
||||
listingStatus = "SOLD";
|
||||
} else if (listing.is_pending) {
|
||||
listingStatus = "PENDING";
|
||||
} else if (listing.is_live) {
|
||||
listingStatus = "ACTIVE";
|
||||
} else if (listing.is_hidden) {
|
||||
listingStatus = "HIDDEN";
|
||||
}
|
||||
|
||||
// Format creation date if available
|
||||
const creationDate = listing.creation_time
|
||||
? new Date(listing.creation_time * 1000).toISOString()
|
||||
: undefined;
|
||||
|
||||
// Extract image and video URLs
|
||||
const imageUrl = listing.primary_listing_photo?.image?.uri;
|
||||
const videoUrl = listing.listing_video ? `https://www.facebook.com/${listing.listing_video.id}/` : undefined;
|
||||
|
||||
// Extract seller information
|
||||
const seller = listing.marketplace_listing_seller ? {
|
||||
name: listing.marketplace_listing_seller.name,
|
||||
id: listing.marketplace_listing_seller.id
|
||||
} : undefined;
|
||||
|
||||
const listingDetails: ListingDetails = {
|
||||
url,
|
||||
title,
|
||||
@@ -453,6 +484,12 @@ function parseFacebookAds(ads: FacebookAdNode[]): ListingDetails[] {
|
||||
address,
|
||||
creationDate,
|
||||
listingType: "item", // Default type for marketplace listings
|
||||
listingStatus,
|
||||
categoryId: listing.marketplace_listing_category_id,
|
||||
imageUrl,
|
||||
videoUrl,
|
||||
seller,
|
||||
deliveryTypes: listing.delivery_types,
|
||||
};
|
||||
|
||||
results.push(listingDetails);
|
||||
|
||||
Reference in New Issue
Block a user