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" }) + } +}