spb/note-spboucher-ai
Public
1import { z } from "zod";2import { handler, parseBody, uuid, HttpError } from "@/lib/api";3import { lookupDoi, addByDoi } from "@/lib/research/references";4import { audit } from "@/lib/audit";5export const maxDuration = 60;6/** GET ?doi=… → Crossref metadata preview (not saved) */7export const GET = handler(async ({ req }) => { const doi = new URL(req.url).searchParams.get("doi"); if (!doi) throw new HttpError(400, "doi missing"); return Response.json(await lookupDoi(doi)); });8/** POST { doi, pageId } → creates (or links) a doi_verified reference */9export const POST = handler(async ({ req, ws, user }) => {10 const b = await parseBody(req, z.object({ doi: z.string().min(5).max(200), pageId: uuid.nullable().optional() }));11 const r = await addByDoi(ws.id, b.doi, b.pageId ?? null);12 await audit(user.id, "reference.doi", { type: "reference", id: r.id }, { doi: r.doi });13 return Response.json(r, { status: 201 });14});15