fix: robust handle extraction — reject non-platform URLs, fix type safety
discover-channels: new extractHandle() validates each handle belongs to its platform (rejects hospital-internal URLs like /idtube/view being treated as YouTube). Extracts handles from full URLs correctly. collect-channel-data: explicit Record<string,unknown> typing for DB JSON fields — fixes TypeScript property access on VerifiedChannels from DB. verifyHandles: fix TikTok double-URL concatenation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
0d72750982
commit
f65f0e85b3
3 files changed
+68
-16
No files matched your search
@@ -73,10 +73,11 @@ Deno.serve(async (req) => {
|
||||
const tasks: Promise<void>[] = [];
|
||||
|
||||
// ─── 1. Instagram (multi-account) ───
|
||||
if (APIFY_TOKEN && verified.instagram?.length > 0) {
|
||||
const igVerified = (verified.instagram || []).filter((v: Record<string, unknown>) => v.verified && v.handle);
|
||||
if (APIFY_TOKEN && igVerified.length > 0) {
|
||||
tasks.push((async () => {
|
||||
const accounts: Record<string, unknown>[] = [];
|
||||
for (const ig of verified.instagram.filter(v => v.verified)) {
|
||||
for (const ig of igVerified) {
|
||||
const items = await runApifyActor("apify~instagram-profile-scraper", { usernames: [ig.handle], resultsLimit: 12 }, APIFY_TOKEN);
|
||||
const profile = (items as Record<string, unknown>[])[0];
|
||||
if (profile && !profile.error) {
|
||||
@@ -104,10 +105,11 @@ Deno.serve(async (req) => {
|
||||
}
|
||||
|
||||
// ─── 2. YouTube ───
|
||||
if (YOUTUBE_API_KEY && verified.youtube?.verified) {
|
||||
const ytVerified = verified.youtube as Record<string, unknown> | null;
|
||||
if (YOUTUBE_API_KEY && ytVerified?.verified) {
|
||||
tasks.push((async () => {
|
||||
const YT = "https://www.googleapis.com/youtube/v3";
|
||||
const channelId = verified.youtube!.channelId || "";
|
||||
const channelId = (ytVerified?.channelId as string) || "";
|
||||
if (!channelId) return;
|
||||
|
||||
const chRes = await fetch(`${YT}/channels?part=snippet,statistics,brandingSettings&id=${channelId}&key=${YOUTUBE_API_KEY}`);
|
||||
@@ -154,9 +156,10 @@ Deno.serve(async (req) => {
|
||||
}
|
||||
|
||||
// ─── 3. Facebook ───
|
||||
if (APIFY_TOKEN && verified.facebook?.verified) {
|
||||
const fbVerified = verified.facebook as Record<string, unknown> | null;
|
||||
if (APIFY_TOKEN && fbVerified?.verified) {
|
||||
tasks.push((async () => {
|
||||
const fbUrl = verified.facebook!.url || `https://www.facebook.com/${verified.facebook!.handle}`;
|
||||
const fbUrl = (fbVerified.url as string) || `https://www.facebook.com/${fbVerified.handle}`;
|
||||
const items = await runApifyActor("apify~facebook-pages-scraper", { startUrls: [{ url: fbUrl }] }, APIFY_TOKEN);
|
||||
const page = (items as Record<string, unknown>[])[0];
|
||||
if (page?.title) {
|
||||
@@ -172,13 +175,14 @@ Deno.serve(async (req) => {
|
||||
}
|
||||
|
||||
// ─── 4. 강남언니 ───
|
||||
if (FIRECRAWL_API_KEY && verified.gangnamUnni?.verified && verified.gangnamUnni.url) {
|
||||
const guVerified = verified.gangnamUnni as Record<string, unknown> | null;
|
||||
if (FIRECRAWL_API_KEY && guVerified?.verified && guVerified.url) {
|
||||
tasks.push((async () => {
|
||||
const scrapeRes = await fetch("https://api.firecrawl.dev/v1/scrape", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${FIRECRAWL_API_KEY}` },
|
||||
body: JSON.stringify({
|
||||
url: verified.gangnamUnni!.url,
|
||||
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",
|
||||
@@ -202,7 +206,7 @@ Deno.serve(async (req) => {
|
||||
name: hospital.hospitalName, rating: hospital.rating, ratingScale: "/10",
|
||||
totalReviews: hospital.totalReviews, doctors: (hospital.doctors || []).slice(0, 10),
|
||||
procedures: hospital.procedures || [], address: hospital.address,
|
||||
badges: hospital.badges || [], sourceUrl: verified.gangnamUnni!.url,
|
||||
badges: hospital.badges || [], sourceUrl: guVerified!.url as string,
|
||||
};
|
||||
}
|
||||
})());
|
||||
|
||||
Reference in new issue
Block a user