feat: ai summary api (#1550)

This commit is contained in:
Stephen Zhou 2024-03-12 19:13:34 +08:00 committed by GitHub
parent a0bf66af5f
commit 666d69e1be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
import { getQuery, NextServerResponse } from "~/lib/server-helper"
import { getSummary } from "~/queries/page.server"
export async function GET(req: Request): Promise<Response> {
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" })
}
}