import { AppError, searchPapers } from "@autoscholar/core"; import { PublicSearchQuery } from "@autoscholar/schemas"; import { handler, json, parseQuery } from "@/lib/server/api"; import { db } from "@/lib/server/db"; import { clientIp } from "@/lib/server/ip"; import { publicLimiter } from "@/lib/server/session"; export const runtime = "nodejs"; export const GET = handler(async (req) => { if (!publicLimiter.check(clientIp(req) ?? "public").allowed) throw new AppError("rate_limited", "slow down", 429); const q = parseQuery(req.url, PublicSearchQuery); const res = await searchPapers(db(), q); return json(res, { headers: { "cache-control": "public, max-age=60, stale-while-revalidate=300" } }); });