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
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Normalize an Instagram handle from various input formats to a pure username.
|
||||
* Browser-side copy of supabase/functions/_shared/normalizeHandles.ts
|
||||
*/
|
||||
export function normalizeInstagramHandle(
|
||||
raw: string | null | undefined,
|
||||
): string | null {
|
||||
if (!raw || typeof raw !== 'string') return null;
|
||||
|
||||
let handle = raw.trim();
|
||||
if (!handle) return null;
|
||||
|
||||
if (handle.includes('instagram.com')) {
|
||||
try {
|
||||
const urlStr = handle.startsWith('http') ? handle : `https://${handle}`;
|
||||
const url = new URL(urlStr);
|
||||
const segments = url.pathname.split('/').filter(Boolean);
|
||||
handle = segments[0] || '';
|
||||
} catch {
|
||||
const match = handle.match(/instagram\.com\/([^/?#]+)/);
|
||||
handle = match?.[1] || '';
|
||||
}
|
||||
}
|
||||
|
||||
if (handle.startsWith('@')) {
|
||||
handle = handle.slice(1);
|
||||
}
|
||||
|
||||
handle = handle.replace(/\/+$/, '');
|
||||
|
||||
return handle || null;
|
||||
}
|
||||
Reference in new issue
Block a user