import { getCloudViewer } from "@/app/cloud-auth"; import { updateLaunchGate, type LaunchGateRecord } from "@/db/repository"; import { apiError, readJsonMutation } from "../../respond"; export async function POST(request: Request) { try { const viewer = await getCloudViewer(); if (!viewer) return Response.json({ error: "authentication_required", message: "请先登录" }, { status: 401 }); if (!viewer.isAdmin) return Response.json({ error: "forbidden", message: "没有商业后台权限" }, { status: 403 }); const payload = await readJsonMutation<{ key?: string; status?: LaunchGateRecord["status"]; owner?: string; evidenceUrl?: string; notes?: string; reason?: string; idempotencyKey?: string }>(request); const gate = await updateLaunchGate({ actorId: viewer.userId, key: payload.key ?? "", status: payload.status ?? "blocked", owner: payload.owner ?? "", evidenceUrl: payload.evidenceUrl ?? "", notes: payload.notes ?? "", reason: payload.reason ?? "", idempotencyKey: payload.idempotencyKey ?? "" }); return Response.json({ gate }); } catch (error) { return apiError(error); } }