From 30b98fc74435d4d6e939bf443e773e7945d39caf Mon Sep 17 00:00:00 2001 From: Gigi Date: Mon, 13 Oct 2025 19:49:04 +0200 Subject: [PATCH] refactor(api): improve type safety in youtube-meta handler - Replace 'any' type with proper type annotations - Add explicit type checking for video details response - Improve description field extraction with better type safety - Add comments for better code documentation --- api/youtube-meta.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/youtube-meta.ts b/api/youtube-meta.ts index d9ef0dbe..ee8190e0 100644 --- a/api/youtube-meta.ts +++ b/api/youtube-meta.ts @@ -55,9 +55,13 @@ export default async function handler(req: VercelRequest, res: VercelResponse) { } try { - const details = await getVideoDetails({ videoID: videoId, lang }) - const title = (details as any)?.title || '' - const description = (details as any)?.description || (details as any)?.shortDescription || (details as any)?.descriptionText || '' + const details: unknown = await getVideoDetails({ videoID: videoId, lang }) + // Be tolerant to possible shapes returned by the extractor + const title = (details as { title?: string } | undefined)?.title || '' + const d1 = (details as { description?: string } | undefined)?.description + const d2 = (details as { shortDescription?: string } | undefined)?.shortDescription + const d3 = (details as { descriptionText?: string } | undefined)?.descriptionText + const description = d1 || d2 || d3 || '' // Language order: manual en -> uiLocale -> lang -> any manual, then auto with same order const langs: string[] = Array.from(new Set(['en', uiLocale, lang].filter(Boolean) as string[]))