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:
Haewon KamandClaude Opus 4.6 committed 2026-04-02 13:34:54 +09:00
1 parent 2d6e95c414
commit bd7bc45192
6 files changed
+156 -23

No files matched your search

+4 -2
View File
@@ -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": "*",
@@ -58,12 +59,13 @@ Deno.serve(async (req) => {
const tasks = [];
// 1. Instagram Profile
if (instagramHandle) {
const cleanIgHandle = normalizeInstagramHandle(instagramHandle);
if (cleanIgHandle) {
tasks.push(
(async () => {
const items = await runApifyActor(
"apify~instagram-profile-scraper",
{ usernames: [instagramHandle], resultsLimit: 12 },
{ usernames: [cleanIgHandle], resultsLimit: 12 },
APIFY_TOKEN
);
const profile = (items as Record<string, unknown>[])[0];