fix: add Authorization header to all Edge Function calls + fix Vision Analysis

- All fetch calls to Supabase Edge Functions now include
  Authorization: Bearer <anon_key> (was missing → 401 errors)
- Fix Firecrawl screenshot API: remove invalid screenshotOptions,
  use "screenshot@fullPage" format (v2 API compatibility)
- Fix screenshot response handling: v2 returns URL not base64,
  now downloads and converts to base64 for Gemini Vision
- Add about page to Vision Analysis capture targets
- Add retry utility, channel error tracking, pipeline resume,
  enrichment retry, EmptyState improvements (Sprint 2-3)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Opus 4.6 committed 2026-04-05 10:08:03 +09:00
1 parent 2f2aa5a5b6
commit 79950925a1
12 files changed
+961 -214

No files matched your search

+49 -14
View File
@@ -5,7 +5,7 @@
export interface VerifiedChannel {
handle: string;
verified: boolean;
verified: boolean | "unverifiable";
url?: string;
channelId?: string; // YouTube channel ID if resolved
}
@@ -28,17 +28,36 @@ async function verifyInstagram(handle: string): Promise<VerifiedChannel> {
const url = `https://www.instagram.com/${handle}/`;
const res = await fetch(url, {
method: 'GET',
headers: { 'User-Agent': 'Mozilla/5.0' },
redirect: 'follow',
headers: { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)' },
redirect: 'manual', // Don't follow redirects — detect login page
});
// Instagram returns 200 for existing profiles, 404 for missing
return {
handle,
verified: res.status === 200,
url,
};
// 302/301 to login page → Instagram blocks unauthenticated access
if (res.status === 301 || res.status === 302) {
const location = res.headers.get('location') || '';
if (location.includes('/accounts/login') || location.includes('/challenge')) {
return { handle, verified: 'unverifiable', url };
}
}
// 200 → profile exists; 404 → definitely not found
if (res.status === 200) {
// Double-check: some 200 responses are actually the login page
const bodySnippet = await res.text().then(t => t.slice(0, 2000)).catch(() => '');
if (bodySnippet.includes('/accounts/login') && !bodySnippet.includes(`"username":"${handle}"`)) {
return { handle, verified: 'unverifiable', url };
}
return { handle, verified: true, url };
}
if (res.status === 404) {
return { handle, verified: false, url };
}
// Any other status → unverifiable (don't assume it doesn't exist)
return { handle, verified: 'unverifiable', url };
} catch {
return { handle, verified: false };
return { handle, verified: 'unverifiable' };
}
}
@@ -86,14 +105,30 @@ async function verifyYouTube(handle: string, apiKey: string): Promise<VerifiedCh
async function verifyFacebook(handle: string): Promise<VerifiedChannel> {
try {
const url = `https://www.facebook.com/${handle}/`;
// Use GET instead of HEAD — Facebook blocks HEAD requests
const res = await fetch(url, {
method: 'HEAD',
headers: { 'User-Agent': 'Mozilla/5.0' },
method: 'GET',
headers: { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)' },
redirect: 'follow',
});
return { handle, verified: res.status === 200, url };
if (res.status === 200) {
// Check if it's a real page or a redirect to login/error
const bodySnippet = await res.text().then(t => t.slice(0, 3000)).catch(() => '');
if (bodySnippet.includes('page_not_found') || bodySnippet.includes('This content isn')) {
return { handle, verified: false, url };
}
return { handle, verified: true, url };
}
if (res.status === 404) {
return { handle, verified: false, url };
}
// Facebook often blocks bots → unverifiable, not false
return { handle, verified: 'unverifiable', url };
} catch {
return { handle, verified: false };
return { handle, verified: 'unverifiable' };
}
}