spb/note-spboucher-ai
Public
1import { handler } from "@/lib/api";2import { buildGraph } from "@/lib/graph/service";3import { NODE_KINDS, type NodeKind } from "@/lib/graph/types";45/** GET /api/graph?types=page,database§ion=notes&since=ISO&pageId=&depth=1&hideOrphans=1&suggestions=0 */6export const GET = handler(async ({ req, ws }) => {7 const u = new URL(req.url).searchParams;8 const types = (u.get("types") ?? "").split(",").map((s) => s.trim()).filter((s): s is NodeKind => (NODE_KINDS as string[]).includes(s));9 const since = u.get("since") ? new Date(u.get("since")!) : null;10 const pageId = u.get("pageId"); const depth = Math.min(4, Math.max(0, Number(u.get("depth") ?? 1) || 1));11 const g = await buildGraph(ws.id, {12 types: types.length ? types : undefined, section: u.get("section") || null, since: since && !isNaN(since.getTime()) ? since : null,13 pageId: pageId && /^[0-9a-f-]{36}$/.test(pageId) ? pageId : null, depth, hideOrphans: u.get("hideOrphans") === "1", suggestions: u.get("suggestions") !== "0",14 });15 return Response.json(g, { headers: { "cache-control": "private, no-store" } });16});17