feat: 스크린샷 리포트 반영 + 영구 저장 인프라 강화
- transformReport: channel_data.screenshots → report.screenshots 자동 매핑 - transformReport: youtubeAudit/instagramAudit/facebookAudit diagnosis에 evidenceIds 자동 연결 (채널별 스크린샷 → 진단 항목 연결) - collect-channel-data: 스크린샷 아카이브를 병렬→순차로 변경 (rate-limit 방지), 실패 시 상세 로그 - scripts/archive-screenshots.py: 기존 GCS 임시 URL → Supabase Storage 일괄 재아카이브 스크립트 추가 - TypeScript 기존 에러 3개 수정 (SectionErrorBoundary, ClinicSnapshot, reviewCount 유니언 타입) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
2d1937944a
commit
9c4d10609f
5 files changed
+292
-37
No files matched your search
@@ -638,60 +638,52 @@ Deno.serve(async (req) => {
|
||||
throw new Error(`No screenshots captured: ${debugInfo}`);
|
||||
}
|
||||
|
||||
// ─── Step 2: Archive to Supabase Storage (replace 7-day GCS URLs) ───────
|
||||
// Firecrawl returns signed GCS URLs that expire after ~7 days.
|
||||
// We already have the image as base64 in memory — upload it permanently
|
||||
// to Supabase Storage and replace ss.url in-place before storing to DB.
|
||||
//
|
||||
// Upload happens in parallel; failures are non-fatal — the screenshot
|
||||
// keeps its GCS URL as a fallback so Vision analysis still proceeds.
|
||||
// clinics/{domain}/{reportId}/screenshots/{id}.png
|
||||
// ─── Step 2: Archive to Supabase Storage (GCS 7일 임시 URL → 영구 저장) ──
|
||||
// base64가 메모리에 있는 지금 즉시 업로드. 실패 시 GCS URL 유지(비치명적).
|
||||
// 경로: clinics/{domain}/{reportId}/screenshots/{id}.png
|
||||
const domain = (() => {
|
||||
try { return new URL(row.url || "").hostname.replace('www.', ''); } catch { return "unknown"; }
|
||||
try {
|
||||
const h = new URL(row.url || "").hostname.replace('www.', '');
|
||||
return h || "unknown";
|
||||
} catch { return "unknown"; }
|
||||
})();
|
||||
const SUPABASE_STORAGE_BUCKET = "screenshots";
|
||||
const archiveTasks = screenshots.map(async (ss) => {
|
||||
if (!ss.base64) return; // no image data — skip
|
||||
|
||||
// 순차 업로드 (병렬 시 Supabase rate-limit 위험 방지)
|
||||
for (const ss of screenshots) {
|
||||
if (!ss.base64) {
|
||||
console.warn(`[archive] ${ss.id}: base64 없음 — GCS URL 유지`);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
// base64 → Uint8Array
|
||||
const binaryStr = atob(ss.base64);
|
||||
const bytes = new Uint8Array(binaryStr.length);
|
||||
for (let i = 0; i < binaryStr.length; i++) {
|
||||
bytes[i] = binaryStr.charCodeAt(i);
|
||||
}
|
||||
for (let i = 0; i < binaryStr.length; i++) bytes[i] = binaryStr.charCodeAt(i);
|
||||
|
||||
// Upload: clinics/{domain}/{reportId}/screenshots/{screenshotId}.png
|
||||
const storagePath = `clinics/${domain}/${reportId}/screenshots/${ss.id}.png`;
|
||||
const { error: uploadError } = await supabase.storage
|
||||
.from(SUPABASE_STORAGE_BUCKET)
|
||||
.upload(storagePath, bytes, {
|
||||
contentType: "image/png",
|
||||
upsert: true, // overwrite if re-running same analysis
|
||||
});
|
||||
.upload(storagePath, bytes, { contentType: "image/png", upsert: true });
|
||||
|
||||
if (uploadError) {
|
||||
// Non-fatal: log and keep GCS URL as fallback
|
||||
console.warn(`[archive] Storage upload failed for ${ss.id}: ${uploadError.message}`);
|
||||
return;
|
||||
console.error(`[archive] ❌ 업로드 실패 ${ss.id}: ${uploadError.message}`);
|
||||
continue; // GCS URL 유지
|
||||
}
|
||||
|
||||
// Replace GCS temp URL with permanent Supabase Storage public URL
|
||||
const { data: { publicUrl } } = supabase.storage
|
||||
.from(SUPABASE_STORAGE_BUCKET)
|
||||
.getPublicUrl(storagePath);
|
||||
|
||||
ss.url = publicUrl; // in-place replace — all downstream code uses permanent URL
|
||||
console.log(`[archive] ${ss.id} → clinics/${domain}/${reportId}/screenshots/`);
|
||||
} catch (archiveErr) {
|
||||
// Non-fatal: Vision analysis still proceeds with base64
|
||||
console.warn(`[archive] Exception for ${ss.id}:`, archiveErr instanceof Error ? archiveErr.message : archiveErr);
|
||||
ss.url = publicUrl;
|
||||
ss.archived = true;
|
||||
console.log(`[archive] ✅ ${ss.id} → Supabase Storage`);
|
||||
} catch (err) {
|
||||
console.error(`[archive] ❌ 예외 ${ss.id}:`, err instanceof Error ? err.message : err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await Promise.allSettled(archiveTasks);
|
||||
|
||||
const archivedCount = screenshots.filter(ss => ss.url.includes("supabase")).length;
|
||||
console.log(`[archive] ${archivedCount}/${screenshots.length} screenshots archived to Supabase Storage`);
|
||||
const archivedCount = screenshots.filter(ss => ss.archived).length;
|
||||
console.log(`[archive] ${archivedCount}/${screenshots.length}개 영구 저장 완료`);
|
||||
|
||||
// Step 3: Run Gemini Vision on captured screenshots (base64 still in memory)
|
||||
if (GEMINI_API_KEY && screenshots.length > 0) {
|
||||
|
||||
Reference in new issue
Block a user