From 666d69e1bed83935b9bd37f12facf85e5be43fa1 Mon Sep 17 00:00:00 2001 From: Stephen Zhou Date: Tue, 12 Mar 2024 19:13:34 +0800 Subject: [PATCH] feat: ai summary api (#1550) --- src/app/api/ai-summary/route.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/app/api/ai-summary/route.ts diff --git a/src/app/api/ai-summary/route.ts b/src/app/api/ai-summary/route.ts new file mode 100644 index 00000000..b31dd1a2 --- /dev/null +++ b/src/app/api/ai-summary/route.ts @@ -0,0 +1,23 @@ +import { getQuery, NextServerResponse } from "~/lib/server-helper" +import { getSummary } from "~/queries/page.server" + +export async function GET(req: Request): Promise { + const query = getQuery(req) + const res = new NextServerResponse() + if (!query.cid || typeof query.cid !== "string") { + return res.status(400).json({ error: "Missing cid" }) + } + if (!query.lang || typeof query.lang !== "string") { + return res.status(400).json({ error: "Missing lang" }) + } + + try { + const summary = await getSummary({ + cid: query.cid, + lang: query.lang, + }) + return res.status(200).json({ summary }) + } catch (error) { + return res.status(500).json({ error: "Could not get summary" }) + } +}