feat: Pipeline V2 — 3-phase analysis with verified channel discovery
Restructured the entire analysis pipeline from AI-guessing social handles to deterministic 3-phase discovery + collection + generation. Phase 1 (discover-channels): 3-source channel discovery - Firecrawl scrape: extract social links from HTML - Perplexity search: find handles via web search - URL regex parsing: deterministic link extraction - Handle verification: HEAD requests + YouTube API - DB: creates row with verified_channels + scrape_data Phase 2 (collect-channel-data): 9 parallel data collectors - Instagram (Apify), YouTube (Data API v3), Facebook (Apify) - 강남언니 (Firecrawl), Naver Blog + Place (Naver API) - Google Maps (Apify), Market analysis (Perplexity 4x parallel) - DB: stores ALL raw data in channel_data column Phase 3 (generate-report): AI report from real data - Reads channel_data + analysis_data from DB - Builds channel summary with real metrics - AI generates report using only verified data - V1 backwards compatibility preserved (url-based flow) Supporting changes: - DB migration: status, verified_channels, channel_data columns - _shared/extractSocialLinks.ts: regex-based social link parser - _shared/verifyHandles.ts: multi-platform handle verifier - AnalysisLoadingPage: real 3-phase progress + channel panel - useReport: channel_data column support + V2 enrichment merge - 강남언니 rating: auto-correct 5→10 scale + search fallback - KPIDashboard: navigate() instead of <a href> - Loading text: 20-30초 → 1-2분 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
da267fd744
commit
7557ef774c
14 files changed
+1506
-253
No files matched your search
@@ -80,3 +80,67 @@ export async function scrapeWebsite(url: string, clinicName?: string) {
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// ─── Pipeline V2 API Functions ───
|
||||
|
||||
/**
|
||||
* Phase 1: Discover & verify social channels from website URL.
|
||||
* Returns verified handles + reportId for subsequent phases.
|
||||
*/
|
||||
export async function discoverChannels(url: string, clinicName?: string) {
|
||||
const response = await fetch(
|
||||
`${supabaseUrl}/functions/v1/discover-channels`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ url, clinicName }),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Channel discovery failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 2: Collect all channel data using verified handles.
|
||||
* Reads verified_channels from DB, runs parallel API calls.
|
||||
*/
|
||||
export async function collectChannelData(reportId: string) {
|
||||
const response = await fetch(
|
||||
`${supabaseUrl}/functions/v1/collect-channel-data`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ reportId }),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Data collection failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 3: Generate AI report using real collected data from DB.
|
||||
*/
|
||||
export async function generateReportV2(reportId: string) {
|
||||
const response = await fetch(
|
||||
`${supabaseUrl}/functions/v1/generate-report`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ reportId }),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Report generation failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
@@ -453,7 +453,11 @@ export function transformApiReport(
|
||||
rating: 0,
|
||||
reviewCount: 0,
|
||||
},
|
||||
overallRating: r.channelAnalysis?.gangnamUnni?.rating ?? 0,
|
||||
// 강남언니 is 10-point scale. AI sometimes gives 5-point — auto-correct.
|
||||
overallRating: (() => {
|
||||
const raw = r.channelAnalysis?.gangnamUnni?.rating ?? 0;
|
||||
return typeof raw === 'number' && raw > 0 && raw <= 5 ? raw * 2 : raw;
|
||||
})(),
|
||||
totalReviews: r.channelAnalysis?.gangnamUnni?.reviews ?? 0,
|
||||
priceRange: { min: '-', max: '-', currency: '₩' },
|
||||
certifications: [],
|
||||
@@ -529,8 +533,12 @@ export function transformApiReport(
|
||||
}] : []),
|
||||
...(r.channelAnalysis?.gangnamUnni ? [{
|
||||
name: '강남언니',
|
||||
status: (r.channelAnalysis.gangnamUnni.status === 'active' ? 'active' : 'inactive') as 'active' | 'inactive',
|
||||
details: `평점: ${r.channelAnalysis.gangnamUnni.rating ?? '-'} / 리뷰: ${r.channelAnalysis.gangnamUnni.reviews ?? '-'}`,
|
||||
status: (r.channelAnalysis.gangnamUnni.status === 'active' || r.channelAnalysis.gangnamUnni.rating ? 'active' : 'inactive') as 'active' | 'inactive',
|
||||
details: (() => {
|
||||
const raw = r.channelAnalysis?.gangnamUnni?.rating;
|
||||
const rating = typeof raw === 'number' && raw > 0 && raw <= 5 ? raw * 2 : raw;
|
||||
return `평점: ${rating ?? '-'}/10 / 리뷰: ${r.channelAnalysis?.gangnamUnni?.reviews ?? '-'}`;
|
||||
})(),
|
||||
}] : []),
|
||||
],
|
||||
|
||||
|
||||
Reference in new issue
Block a user