/** /api/admin/config — 站点配置读写。 */ import { NextResponse } from "next/server"; import { getSession, verifyCsrf } from "@/lib/auth"; import { CONFIG_KEYS, getSiteConfig, setSiteConfig, type SiteConfig } from "@/lib/siteConfig"; export const runtime = "nodejs"; export async function GET() { if (!(await getSession())) { return NextResponse.json({ error: "未登录" }, { status: 401 }); } return NextResponse.json({ config: getSiteConfig() }); } export async function PUT(req: Request) { if (!(await verifyCsrf())) { return NextResponse.json({ error: "未登录" }, { status: 401 }); } let body: Partial; try { body = await req.json(); } catch { return NextResponse.json({ error: "请求格式错误" }, { status: 400 }); } const patch: Partial> = {}; for (const key of CONFIG_KEYS) { const v = (body as Record)[key]; if (typeof v === "string") patch[key] = v; } setSiteConfig(patch); return NextResponse.json({ ok: true, config: getSiteConfig() }); }