feat: add API Dashboard + filled icons + pipeline improvements
- Add /api-dashboard page with API connection status, env var checker, pipeline flow diagram, and cost estimator - Add 15 new filled SVG icons (Shield, Database, Server, Bolt, Eye, Copy, Check, Cross, Warning, Refresh, Flow, Coin, LinkExternal etc.) - Follow INFINITH design system: no emoji, no line icons, semantic status colors, diagonal shadows, brand gradients, font-serif headings - Improve Vision Analysis with base64 encoding fix - Add SectionErrorBoundary for graceful section-level error handling - Add Google Places API utility (prepared for future migration) - Fix Edge Function auth headers and report generation pipeline Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2ca9ec0306
commit
ec991057e6
20 files changed
+1397
-109
No files matched your search
@@ -4,6 +4,7 @@ import type { VerifiedChannels } from "../_shared/verifyHandles.ts";
|
||||
import { PERPLEXITY_MODEL } from "../_shared/config.ts";
|
||||
import { captureAllScreenshots, runVisionAnalysis, screenshotErrors, type ScreenshotResult } from "../_shared/visionAnalysis.ts";
|
||||
import { fetchWithRetry, fetchJsonWithRetry, wrapChannelTask, type ChannelTaskResult } from "../_shared/retry.ts";
|
||||
import { searchGooglePlace } from "../_shared/googlePlaces.ts";
|
||||
|
||||
const corsHeaders = {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
@@ -77,6 +78,7 @@ Deno.serve(async (req) => {
|
||||
const PERPLEXITY_API_KEY = Deno.env.get("PERPLEXITY_API_KEY") || "";
|
||||
const NAVER_CLIENT_ID = Deno.env.get("NAVER_CLIENT_ID") || "";
|
||||
const NAVER_CLIENT_SECRET = Deno.env.get("NAVER_CLIENT_SECRET") || "";
|
||||
const GOOGLE_PLACES_API_KEY = Deno.env.get("GOOGLE_PLACES_API_KEY") || "";
|
||||
|
||||
const channelData: Record<string, unknown> = {};
|
||||
const analysisData: Record<string, unknown> = {};
|
||||
@@ -116,6 +118,74 @@ Deno.serve(async (req) => {
|
||||
}));
|
||||
}
|
||||
|
||||
// ─── 1b. Instagram Posts (최근 20개 포스트 상세) ───
|
||||
const igPrimaryHandle = igCandidates[0]?.handle as string | undefined;
|
||||
if (APIFY_TOKEN && igPrimaryHandle) {
|
||||
channelTasks.push(wrapChannelTask("instagramPosts", async () => {
|
||||
const handle = igPrimaryHandle.replace(/^@/, '');
|
||||
const items = await runApifyActor(
|
||||
"apify~instagram-post-scraper",
|
||||
{ directUrls: [`https://www.instagram.com/${handle}/`], resultsLimit: 20 },
|
||||
APIFY_TOKEN,
|
||||
);
|
||||
const posts = (items as Record<string, unknown>[]).map(p => ({
|
||||
id: p.id,
|
||||
type: p.type,
|
||||
shortCode: p.shortCode,
|
||||
url: p.url,
|
||||
caption: ((p.caption as string) || '').slice(0, 500),
|
||||
hashtags: p.hashtags || [],
|
||||
mentions: p.mentions || [],
|
||||
likesCount: (p.likesCount as number) || 0,
|
||||
commentsCount: (p.commentsCount as number) || 0,
|
||||
timestamp: p.timestamp,
|
||||
displayUrl: p.displayUrl,
|
||||
}));
|
||||
const totalLikes = posts.reduce((sum, p) => sum + p.likesCount, 0);
|
||||
const totalComments = posts.reduce((sum, p) => sum + p.commentsCount, 0);
|
||||
channelData.instagramPosts = {
|
||||
posts,
|
||||
totalPosts: posts.length,
|
||||
avgLikes: posts.length > 0 ? Math.round(totalLikes / posts.length) : 0,
|
||||
avgComments: posts.length > 0 ? Math.round(totalComments / posts.length) : 0,
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
// ─── 1c. Instagram Reels (최근 15개 릴스 상세) ───
|
||||
if (APIFY_TOKEN && igPrimaryHandle) {
|
||||
channelTasks.push(wrapChannelTask("instagramReels", async () => {
|
||||
const handle = igPrimaryHandle.replace(/^@/, '');
|
||||
const items = await runApifyActor(
|
||||
"apify~instagram-reel-scraper",
|
||||
{ directUrls: [`https://www.instagram.com/${handle}/reels/`], resultsLimit: 15 },
|
||||
APIFY_TOKEN,
|
||||
);
|
||||
const reels = (items as Record<string, unknown>[]).map(r => ({
|
||||
id: r.id,
|
||||
shortCode: r.shortCode,
|
||||
url: r.url,
|
||||
caption: ((r.caption as string) || '').slice(0, 500),
|
||||
hashtags: r.hashtags || [],
|
||||
likesCount: (r.likesCount as number) || 0,
|
||||
commentsCount: (r.commentsCount as number) || 0,
|
||||
videoViewCount: (r.videoViewCount as number) || 0,
|
||||
videoPlayCount: (r.videoPlayCount as number) || 0,
|
||||
videoDuration: (r.videoDuration as number) || 0,
|
||||
timestamp: r.timestamp,
|
||||
musicInfo: r.musicInfo || null,
|
||||
}));
|
||||
const totalViews = reels.reduce((sum, r) => sum + r.videoViewCount, 0);
|
||||
const totalPlays = reels.reduce((sum, r) => sum + r.videoPlayCount, 0);
|
||||
channelData.instagramReels = {
|
||||
reels,
|
||||
totalReels: reels.length,
|
||||
avgViews: reels.length > 0 ? Math.round(totalViews / reels.length) : 0,
|
||||
avgPlays: reels.length > 0 ? Math.round(totalPlays / reels.length) : 0,
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
// ─── 2. YouTube ───
|
||||
const ytVerified = verified.youtube as Record<string, unknown> | null;
|
||||
if (YOUTUBE_API_KEY && (ytVerified?.verified === true || ytVerified?.verified === "unverifiable")) {
|
||||
@@ -307,28 +377,19 @@ Deno.serve(async (req) => {
|
||||
}));
|
||||
}
|
||||
|
||||
// ─── 6. Google Maps ───
|
||||
if (APIFY_TOKEN && clinicName) {
|
||||
// ─── 6. Google Maps (Google Places API New) ───
|
||||
if (GOOGLE_PLACES_API_KEY && clinicName) {
|
||||
channelTasks.push(wrapChannelTask("googleMaps", async () => {
|
||||
const queries = [`${clinicName} 성형외과`, clinicName, `${clinicName} ${address || "강남"}`];
|
||||
let items: unknown[] = [];
|
||||
for (const q of queries) {
|
||||
items = await runApifyActor("compass~crawler-google-places", {
|
||||
searchStringsArray: [q], maxCrawledPlacesPerSearch: 3, language: "ko", maxReviews: 10,
|
||||
}, APIFY_TOKEN);
|
||||
if ((items as Record<string, unknown>[]).length > 0) break;
|
||||
}
|
||||
const place = (items as Record<string, unknown>[])[0];
|
||||
const place = await searchGooglePlace(clinicName, address || undefined, GOOGLE_PLACES_API_KEY);
|
||||
if (place) {
|
||||
channelData.googleMaps = {
|
||||
name: place.title, rating: place.totalScore, reviewCount: place.reviewsCount,
|
||||
name: place.name, rating: place.rating, reviewCount: place.reviewCount,
|
||||
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,
|
||||
})),
|
||||
clinicWebsite: place.clinicWebsite,
|
||||
mapsUrl: place.mapsUrl,
|
||||
placeId: place.placeId,
|
||||
category: place.category, openingHours: place.openingHours,
|
||||
topReviews: place.topReviews,
|
||||
};
|
||||
} else {
|
||||
throw new Error("Google Maps: no matching place found");
|
||||
|
||||
Reference in new issue
Block a user