fix: Instagram data collection pipeline — handle normalization + DB persistence
- Add normalizeInstagramHandle() utility (Edge + browser) to strip URLs, @ prefixes - generate-report: normalize handles before saving, persist socialHandles in report JSONB - enrich-channels: normalize Instagram handle before Apify call (defense in depth) - useReport: recover socialHandles + channelEnrichment from DB on direct URL access - ReportPage: skip redundant enrichment when data already exists in DB Fixes: Instagram enrichment failing due to URL-format handles passed to Apify Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2d6e95c414
commit
bd7bc45192
6 files changed
+156
-23
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import "@supabase/functions-js/edge-runtime.d.ts";
|
||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2";
|
||||
import { normalizeInstagramHandle } from "../_shared/normalizeHandles.ts";
|
||||
|
||||
const corsHeaders = {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
@@ -153,6 +154,18 @@ ${JSON.stringify(analyzeResult.data?.analysis || {}, null, 2)}
|
||||
report = { raw: reportText, parseError: true };
|
||||
}
|
||||
|
||||
// Normalize social handles from scrape data
|
||||
const socialMedia = clinic.socialMedia || {};
|
||||
const normalizedHandles = {
|
||||
instagram: normalizeInstagramHandle(socialMedia.instagram),
|
||||
youtube: socialMedia.youtube || null,
|
||||
facebook: socialMedia.facebook || null,
|
||||
blog: socialMedia.blog || null,
|
||||
};
|
||||
|
||||
// Embed normalized handles in report for DB persistence
|
||||
report.socialHandles = normalizedHandles;
|
||||
|
||||
// Save to Supabase
|
||||
const supabase = createClient(supabaseUrl, supabaseKey);
|
||||
const { data: saved, error: saveError } = await supabase
|
||||
@@ -167,9 +180,6 @@ ${JSON.stringify(analyzeResult.data?.analysis || {}, null, 2)}
|
||||
.select("id")
|
||||
.single();
|
||||
|
||||
// Extract social handles from scrape data for frontend enrichment
|
||||
const socialMedia = clinic.socialMedia || {};
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
@@ -184,12 +194,7 @@ ${JSON.stringify(analyzeResult.data?.analysis || {}, null, 2)}
|
||||
marketAnalysis: analyzeResult.success,
|
||||
aiGeneration: !report.parseError,
|
||||
},
|
||||
socialHandles: {
|
||||
instagram: socialMedia.instagram || null,
|
||||
youtube: socialMedia.youtube || null,
|
||||
facebook: socialMedia.facebook || null,
|
||||
blog: socialMedia.blog || null,
|
||||
},
|
||||
socialHandles: normalizedHandles,
|
||||
address,
|
||||
services,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user