/** /api/admin/services — 服务项目管理。 */ import { NextResponse } from "next/server"; import { getSession, verifyCsrf } from "@/lib/auth"; import { listServices, upsertService } from "@/lib/siteConfig"; export const runtime = "nodejs"; export async function GET() { if (!(await getSession())) { return NextResponse.json({ error: "未登录" }, { status: 401 }); } return NextResponse.json({ services: listServices(false) }); } export async function POST(req: Request) { if (!(await verifyCsrf())) { return NextResponse.json({ error: "未登录" }, { status: 401 }); } let body: { id?: number; title?: string; description?: string; price_note?: string; sort_order?: number; enabled?: number; }; try { body = await req.json(); } catch { return NextResponse.json({ error: "请求格式错误" }, { status: 400 }); } const title = String(body.title ?? "").trim(); if (!title) { return NextResponse.json({ error: "服务名称必填" }, { status: 400 }); } const row = upsertService({ id: body.id, title, description: body.description, price_note: body.price_note, sort_order: body.sort_order, enabled: body.enabled, }); return NextResponse.json({ ok: true, service: row }); }