|
@@ -225,11 +225,41 @@ Deno.serve(async (req) => {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
const shopData = await scraperClient.getShop(store.id);
|
|
const shopData = await scraperClient.getShop(store.id);
|
|
|
|
|
+
|
|
|
|
|
+ // Transform the scraper API response to match UI expectations
|
|
|
|
|
+ const transformedData = {
|
|
|
|
|
+ id: shopData.shop?.id || store.id,
|
|
|
|
|
+ url: shopData.shop?.url || store.store_url,
|
|
|
|
|
+ custom_id: shopData.shop?.custom_id,
|
|
|
|
|
+ status: (shopData.scheduled_jobs && shopData.scheduled_jobs.some((job: any) => job.enabled && job.status !== 'completed'))
|
|
|
|
|
+ ? 'active' as const
|
|
|
|
|
+ : 'inactive' as const,
|
|
|
|
|
+ last_scraped_at: shopData.analytics?.last_scraped_at,
|
|
|
|
|
+ next_scheduled_scrape: shopData.analytics?.next_scrape_at,
|
|
|
|
|
+ scheduled_enabled: shopData.scheduled_jobs?.some((job: any) => job.enabled) || false,
|
|
|
|
|
+ total_urls_found: shopData.analytics?.total_urls_found || 0,
|
|
|
|
|
+ total_content_items: (
|
|
|
|
|
+ (shopData.content_metadata?.shipping_informations?.length || 0) +
|
|
|
|
|
+ (shopData.content_metadata?.contacts?.length || 0) +
|
|
|
|
|
+ (shopData.content_metadata?.terms_of_conditions?.length || 0) +
|
|
|
|
|
+ (shopData.content_metadata?.faq?.length || 0)
|
|
|
|
|
+ ),
|
|
|
|
|
+ scrape_count: shopData.analytics?.total_scrapes || 0,
|
|
|
|
|
+ analytics: {
|
|
|
|
|
+ shipping_count: shopData.content_metadata?.shipping_informations?.length || 0,
|
|
|
|
|
+ contacts_count: shopData.content_metadata?.contacts?.length || 0,
|
|
|
|
|
+ terms_count: shopData.content_metadata?.terms_of_conditions?.length || 0,
|
|
|
|
|
+ faq_count: shopData.content_metadata?.faq?.length || 0,
|
|
|
|
|
+ },
|
|
|
|
|
+ created_at: shopData.shop?.created_at,
|
|
|
|
|
+ updated_at: shopData.shop?.updated_at,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return new Response(
|
|
return new Response(
|
|
|
JSON.stringify({
|
|
JSON.stringify({
|
|
|
registered: true,
|
|
registered: true,
|
|
|
enabled: store.scraper_enabled,
|
|
enabled: store.scraper_enabled,
|
|
|
- shop_data: shopData,
|
|
|
|
|
|
|
+ shop_data: transformedData,
|
|
|
}),
|
|
}),
|
|
|
{ status: 200, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
|
{ status: 200, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
|
|
);
|
|
);
|
|
@@ -290,10 +320,44 @@ Deno.serve(async (req) => {
|
|
|
if (dateTo) filter.date_to = dateTo;
|
|
if (dateTo) filter.date_to = dateTo;
|
|
|
if (limit) filter.limit = parseInt(limit, 10);
|
|
if (limit) filter.limit = parseInt(limit, 10);
|
|
|
|
|
|
|
|
- const content = await scraperClient.getShopContent(store.id, filter);
|
|
|
|
|
|
|
+ const rawContent = await scraperClient.getShopContent(store.id, filter);
|
|
|
|
|
+
|
|
|
|
|
+ // Transform the scraper API response to match UI expectations
|
|
|
|
|
+ const contentArray: any[] = [];
|
|
|
|
|
+ const results = rawContent.results || {};
|
|
|
|
|
+
|
|
|
|
|
+ // Helper function to transform content items
|
|
|
|
|
+ const transformContentItems = (items: any[], type: string) => {
|
|
|
|
|
+ return (items || []).map((item: any, index: number) => ({
|
|
|
|
|
+ id: `${type}-${index}-${item.url}`,
|
|
|
|
|
+ url: item.url,
|
|
|
|
|
+ content_type: type,
|
|
|
|
|
+ title: item.url.split('/').pop()?.replace(/-/g, ' ') || type,
|
|
|
|
|
+ content: item.content || '',
|
|
|
|
|
+ scraped_at: item.last_updated || new Date().toISOString(),
|
|
|
|
|
+ metadata: {
|
|
|
|
|
+ changed: item.changed,
|
|
|
|
|
+ last_updated: item.last_updated,
|
|
|
|
|
+ },
|
|
|
|
|
+ }));
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // Map content type names from API to UI format
|
|
|
|
|
+ if (results.shipping_informations) {
|
|
|
|
|
+ contentArray.push(...transformContentItems(results.shipping_informations, 'shipping'));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (results.contacts) {
|
|
|
|
|
+ contentArray.push(...transformContentItems(results.contacts, 'contacts'));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (results.terms_of_conditions) {
|
|
|
|
|
+ contentArray.push(...transformContentItems(results.terms_of_conditions, 'terms'));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (results.faq) {
|
|
|
|
|
+ contentArray.push(...transformContentItems(results.faq, 'faq'));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return new Response(
|
|
return new Response(
|
|
|
- JSON.stringify(content),
|
|
|
|
|
|
|
+ JSON.stringify({ content: contentArray }),
|
|
|
{ status: 200, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
|
{ status: 200, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|