SPB Git
1.0 KB · 13 lines typescript
1import { handler } from "@/lib/api";2import { exportBibtex } from "@/lib/research/references";3import { db, schema } from "@/db";4import { eq } from "drizzle-orm";5/** GET ?pageId=<id> → references.bib of that page; without pageId → whole library. ?inline=1 returns text without attachment header. */6export const GET = handler(async ({ req, ws }) => {7  const u = new URL(req.url); const pageId = u.searchParams.get("pageId"); const inline = u.searchParams.get("inline") === "1";8  const bib = await exportBibtex(ws.id, pageId || null);9  let name = "library";10  if (pageId) { const [p] = await db.select({ title: schema.pages.title }).from(schema.pages).where(eq(schema.pages.id, pageId)); name = (p?.title ?? "references").toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "").slice(0, 60) || "references"; }11  return new Response(bib, { headers: { "content-type": "application/x-bibtex; charset=utf-8", ...(inline ? {} : { "content-disposition": `attachment; filename="${name}.bib"` }) } });12});13
Files · main
Menu

Theme