From 3f865656a98f42a02639fcfb74e78b03acd44b55 Mon Sep 17 00:00:00 2001 From: JimmyLv Date: Mon, 27 Feb 2023 11:51:53 +0800 Subject: [PATCH] feat: throw error --- pages/[...slug].tsx | 3 ++- pages/api/summarize.ts | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pages/[...slug].tsx b/pages/[...slug].tsx index dd4fd464..b74f29ca 100644 --- a/pages/[...slug].tsx +++ b/pages/[...slug].tsx @@ -57,6 +57,7 @@ export const Home: NextPage = () => { if (!response.ok) { console.log("error", response.statusText); + toast.error("啊叻?视频字幕不见了?!"); return; } @@ -151,7 +152,7 @@ export const Home: NextPage = () => { {summary && (

- 【总结】 + 【📝 总结】

{summary.split("- ").map((sentence, index) => ( diff --git a/pages/api/summarize.ts b/pages/api/summarize.ts index 762ca4cd..02d9cbeb 100644 --- a/pages/api/summarize.ts +++ b/pages/api/summarize.ts @@ -35,6 +35,9 @@ export default async function handler(req: Request) { const title = res.data.title; const subtitleUrl = res.data.subtitle?.list?.[0]?.subtitle_url; console.log("subtitle_url", subtitleUrl); + if (!subtitleUrl) { + return new Response("No subtitle in the video", { status: 500 }); + } const subtitleResponse = await fetch(subtitleUrl); const subtitles = await subtitleResponse.json(); @@ -46,7 +49,7 @@ export default async function handler(req: Request) { timestamp: item.from, }; }); - console.log("========transcripts========", transcripts); + // console.log("========transcripts========", transcripts); const text = getChunckedTranscripts(transcripts, transcripts); const prompt = getSummaryPrompt(title, text);