feat: Sprint 1 — 7 data quality quick wins

WP-1: YouTube channel ID regex {20,} → {22} (exactly 24 chars)
WP-2: Naver Place category filtering in enrich-channels (성형/피부)
WP-3: Google Maps stores mapsUrl separately from clinicWebsite
WP-4: Naver Blog separates officialBlogUrl from search results
WP-5: 강남언니 rawRating + normalized rating (≤5 → ×2), Firecrawl
      prompt explicitly states "out of 10, NOT out of 5"
WP-6: Perplexity model centralized in _shared/config.ts (env override)
WP-7: Apify Instagram timeout 30s → 45s

Frontend: transformReport uses mapsUrl and officialBlogUrl when available

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Opus 4.6 committed 2026-04-04 23:35:40 +09:00
1 parent 1071328574
commit 80c57147e7
8 files changed
+80 -39

No files matched your search

@@ -1,6 +1,7 @@
import "@supabase/functions-js/edge-runtime.d.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js@2";
import type { VerifiedChannels } from "../_shared/verifyHandles.ts";
import { PERPLEXITY_MODEL } from "../_shared/config.ts";
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
@@ -200,7 +201,7 @@ Deno.serve(async (req) => {
url: guVerified!.url as string,
formats: ["json"],
jsonOptions: {
prompt: "Extract: hospital name, overall rating (out of 10), total review count, doctors with names/ratings/review counts/specialties, procedures offered, address, certifications/badges",
prompt: "Extract: hospital name, overall rating (강남언니 rating is always out of 10, NOT out of 5), total review count, doctors with names/ratings/review counts/specialties, procedures offered, address, certifications/badges",
schema: {
type: "object",
properties: {
@@ -218,7 +219,10 @@ Deno.serve(async (req) => {
const hospital = data.data?.json;
if (hospital?.hospitalName) {
channelData.gangnamUnni = {
name: hospital.hospitalName, rating: hospital.rating, ratingScale: "/10",
name: hospital.hospitalName,
rawRating: hospital.rating,
rating: typeof hospital.rating === 'number' && hospital.rating > 0 && hospital.rating <= 5 ? hospital.rating * 2 : hospital.rating,
ratingScale: "/10",
totalReviews: hospital.totalReviews, doctors: (hospital.doctors || []).slice(0, 10),
procedures: hospital.procedures || [], address: hospital.address,
badges: hospital.badges || [], sourceUrl: guVerified!.url as string,
@@ -232,12 +236,20 @@ Deno.serve(async (req) => {
const naverHeaders = { "X-Naver-Client-Id": NAVER_CLIENT_ID, "X-Naver-Client-Secret": NAVER_CLIENT_SECRET };
tasks.push((async () => {
// Get verified Naver Blog handle from Phase 1 for official blog URL
const nbVerified = verified.naverBlog as Record<string, unknown> | null;
const officialBlogHandle = nbVerified?.handle ? String(nbVerified.handle) : null;
const query = encodeURIComponent(`${clinicName} 후기`);
const res = await fetch(`https://openapi.naver.com/v1/search/blog.json?query=${query}&display=10&sort=sim`, { headers: naverHeaders });
if (!res.ok) return;
const data = await res.json();
channelData.naverBlog = {
totalResults: data.total || 0, searchQuery: `${clinicName} 후기`,
// Official blog URL from Phase 1 verified handle
officialBlogUrl: officialBlogHandle ? `https://blog.naver.com/${officialBlogHandle}` : null,
officialBlogHandle: officialBlogHandle,
// Blog mentions (third-party posts, NOT the official blog)
posts: (data.items || []).slice(0, 10).map((item: Record<string, string>) => ({
title: (item.title || "").replace(/<[^>]*>/g, ""),
description: (item.description || "").replace(/<[^>]*>/g, ""),
@@ -294,7 +306,9 @@ Deno.serve(async (req) => {
if (place) {
channelData.googleMaps = {
name: place.title, rating: place.totalScore, reviewCount: place.reviewsCount,
address: place.address, phone: place.phone, website: place.website,
address: place.address, phone: place.phone,
clinicWebsite: place.website, // clinic's own website (not Maps URL)
mapsUrl: place.url || (place.title ? `https://www.google.com/maps/search/${encodeURIComponent(String(place.title))}` : ''),
category: place.categoryName, openingHours: place.openingHours,
topReviews: ((place.reviews as Record<string, unknown>[]) || []).slice(0, 10).map(r => ({
stars: r.stars, text: r.text, publishedAtDate: r.publishedAtDate,
@@ -319,7 +333,7 @@ Deno.serve(async (req) => {
method: "POST",
headers: { "Content-Type": "application/json", Authorization: `Bearer ${PERPLEXITY_API_KEY}` },
body: JSON.stringify({
model: "sonar", messages: [
model: PERPLEXITY_MODEL, messages: [
{ role: "system", content: "You are a Korean medical marketing analyst. Always respond in Korean. Provide data in valid JSON format." },
{ role: "user", content: q.prompt },
], temperature: 0.3,