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
@@ -550,7 +550,7 @@ export function transformApiReport(
|
||||
name: doctor?.name || '',
|
||||
credentials: doctor?.specialty || '',
|
||||
rating: doctor?.rating ?? 0,
|
||||
reviewCount: doctor?.reviewCount ?? doctor?.reviews ?? 0,
|
||||
reviewCount: (doctor as { reviewCount?: number })?.reviewCount ?? (doctor as { reviews?: number })?.reviews ?? 0,
|
||||
},
|
||||
// 강남언니 is 10-point scale. AI sometimes gives 5-point — auto-correct.
|
||||
overallRating: (() => {
|
||||
@@ -746,6 +746,15 @@ export interface EnrichmentData {
|
||||
badges?: string[];
|
||||
sourceUrl?: string;
|
||||
};
|
||||
// 스크래핑 시 캡처된 스크린샷 목록 (channel_data.screenshots)
|
||||
screenshots?: {
|
||||
id: string;
|
||||
url: string;
|
||||
channel: string;
|
||||
caption: string;
|
||||
capturedAt?: string;
|
||||
sourceUrl?: string;
|
||||
}[];
|
||||
naverBlog?: {
|
||||
totalResults?: number;
|
||||
searchQuery?: string;
|
||||
@@ -1119,7 +1128,7 @@ export function mergeEnrichment(
|
||||
linkedDomain: fb.website || '',
|
||||
reviews: (() => {
|
||||
// Facebook rating 문자열 파싱: "Not yet rated (3 Reviews)" or "4.8 (120 Reviews)"
|
||||
const m = (fb.rating || '').match(/\((\d+)\s+Reviews?\)/i);
|
||||
const m = String(fb.rating || '').match(/\((\d+)\s+Reviews?\)/i);
|
||||
return m ? parseInt(m[1], 10) : 0;
|
||||
})(),
|
||||
recentPostAge: '',
|
||||
@@ -1178,5 +1187,74 @@ export function mergeEnrichment(
|
||||
merged.problemDiagnosis = [...merged.problemDiagnosis, ...enrichDiagnosis];
|
||||
}
|
||||
|
||||
// ── 스크린샷 영구 반영 ──────────────────────────────────────────────────────
|
||||
// channel_data.screenshots → report.screenshots 로 옮기고,
|
||||
// 채널별로 diagnosis evidenceIds 자동 연결
|
||||
if (enrichment.screenshots?.length) {
|
||||
const ss = enrichment.screenshots;
|
||||
|
||||
// 1) report.screenshots 세팅 (ScreenshotEvidence 형식으로 변환)
|
||||
merged.screenshots = ss.map(s => ({
|
||||
id: s.id,
|
||||
url: s.url,
|
||||
channel: s.channel,
|
||||
caption: s.caption,
|
||||
capturedAt: s.capturedAt ?? new Date().toISOString(),
|
||||
sourceUrl: s.sourceUrl,
|
||||
}));
|
||||
|
||||
// 2) 채널명 → screenshot IDs 매핑 테이블 생성
|
||||
// channel_data의 channel 필드: "YouTube", "웹사이트", "Instagram", "Facebook" 등
|
||||
const CHANNEL_ALIAS: Record<string, string[]> = {
|
||||
youtube: ['youtube', 'YouTube', 'yt'],
|
||||
instagram: ['instagram', 'Instagram', 'ig'],
|
||||
facebook: ['facebook', 'Facebook', 'fb'],
|
||||
website: ['웹사이트', 'website', 'Website'],
|
||||
gangnamUnni: ['강남언니', 'gangnamUnni'],
|
||||
naverPlace: ['네이버 플레이스', 'naverPlace'],
|
||||
naverBlog: ['네이버 블로그', 'naverBlog'],
|
||||
};
|
||||
|
||||
const channelToIds: Record<string, string[]> = {};
|
||||
for (const s of ss) {
|
||||
for (const [key, aliases] of Object.entries(CHANNEL_ALIAS)) {
|
||||
if (aliases.some(a => s.channel.toLowerCase().includes(a.toLowerCase()))) {
|
||||
channelToIds[key] = [...(channelToIds[key] ?? []), s.id];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3) 채널별 audit.diagnosis 배열에 evidenceIds 연결
|
||||
// YouTubeAudit / InstagramAudit / FacebookAudit 컴포넌트가 이 필드를 사용함
|
||||
const linkIds = (diagItems: import('../types/report').DiagnosisItem[], channelKey: string): import('../types/report').DiagnosisItem[] => {
|
||||
const ids = channelToIds[channelKey] ?? [];
|
||||
if (!ids.length) return diagItems;
|
||||
return diagItems.map(item => ({ ...item, evidenceIds: [...(item.evidenceIds ?? []), ...ids] }));
|
||||
};
|
||||
|
||||
if (merged.youtubeAudit?.diagnosis?.length) {
|
||||
merged.youtubeAudit = { ...merged.youtubeAudit, diagnosis: linkIds(merged.youtubeAudit.diagnosis, 'youtube') };
|
||||
}
|
||||
if (merged.instagramAudit?.diagnosis?.length) {
|
||||
merged.instagramAudit = { ...merged.instagramAudit, diagnosis: linkIds(merged.instagramAudit.diagnosis, 'instagram') };
|
||||
}
|
||||
if (merged.facebookAudit?.diagnosis?.length) {
|
||||
merged.facebookAudit = { ...merged.facebookAudit, diagnosis: linkIds(merged.facebookAudit.diagnosis, 'facebook') };
|
||||
}
|
||||
// websiteAudit / 기타 채널은 EvidenceGallery를 직접 받지 않으므로 problemDiagnosis에만 연결
|
||||
merged.problemDiagnosis = merged.problemDiagnosis.map(item => {
|
||||
const catLower = item.category.toLowerCase();
|
||||
let ids: string[] = [];
|
||||
for (const [key, ssIds] of Object.entries(channelToIds)) {
|
||||
if (catLower.includes(key) || key.includes(catLower)) {
|
||||
ids = [...ids, ...ssIds];
|
||||
}
|
||||
}
|
||||
return ids.length > 0 ? { ...item, evidenceIds: ids } : item;
|
||||
});
|
||||
}
|
||||
// ───────────────────────────────────────────────────────────────────────────
|
||||
|
||||
return merged;
|
||||
}
|
||||
Reference in new issue
Block a user