feat: archive Firecrawl screenshots to Supabase Storage (permanent URLs)

## 문제
Firecrawl이 반환하는 스크린샷 URL은 GCS Signed URL로 7일 후 만료.
리포트에 저장된 이미지 URL이 일주일 후 전부 깨짐 (403 Access Denied).

## 해결
collect-channel-data의 Vision 단계에 아카이빙 스텝 추가.
캡처 직후 base64(이미 메모리에 있음)를 Supabase Storage에 영구 업로드.

### 처리 흐름 (변경 후)
1. captureAllScreenshots() → GCS URL + base64 반환 (기존)
2. [신규] archiveTasks: base64 → Supabase Storage 업로드 (병렬)
   - 경로: screenshots/{reportId}/{screenshotId}.png
   - 성공 시 ss.url을 영구 Supabase URL로 in-place 교체
   - 실패 시 non-fatal — GCS URL fallback으로 Vision 분석 계속 진행
3. runVisionAnalysis() — base64 여전히 메모리에 있어 정상 실행 (기존)
4. channelData.screenshots 저장 시 영구 URL 사용 (자동)
   - archived: true/false 플래그 추가 (모니터링용)

### 비용/성능
- 추가 API 호출 없음 (base64 이미 캡처 시 다운로드됨)
- 업로드: ~1-3초/장 (병렬), 5MB limit, PNG/JPEG/WebP 허용
- 버킷: public (URL만 있으면 열람) + 서비스 역할만 업로드 가능

## 마이그레이션
supabase/migrations/20260407_screenshots_storage.sql
- screenshots 버킷 생성 (public, 5MB limit)
- RLS: public read / service_role write
- delete_old_screenshots() 함수: 90일 이상 된 파일 정리 (pg_cron 연동 가능)

## 타입
ScreenshotResult.archived?: boolean 필드 추가 (영구 vs GCS fallback 구분)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Sonnet 4.6 committed 2026-04-07 09:51:31 +09:00
1 parent bcc0b6ea5e
commit 36d2f1cf49
3 files changed
+125 -20

No files matched your search

+6 -2
View File
@@ -19,12 +19,16 @@ const FIRECRAWL_BASE = "https://api.firecrawl.dev/v1";
export interface ScreenshotResult {
id: string;
url: string; // Supabase Storage signed URL or data URI
/** Image URL. Initially a GCS signed URL from Firecrawl (~7-day expiry).
* collect-channel-data archives it to Supabase Storage and replaces this
* with a permanent public URL. Check `archived` flag to know which. */
url: string;
channel: string; // 'website', 'youtube', 'instagram', 'gangnamUnni', etc.
capturedAt: string;
caption: string;
sourceUrl: string; // Original page URL
base64?: string; // Raw base64 (for Vision analysis, not stored in report)
base64?: string; // Raw base64 (for Vision analysis — NOT stored in report or DB)
archived?: boolean; // true = permanent Supabase Storage URL; false = GCS fallback
}
export interface VisionAnalysisResult {