import { getCloudViewer } from "@/app/cloud-auth"; import { runRetentionMaintenance } 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<{ confirmed?: boolean; reason?: string; }>(request); const retention = await runRetentionMaintenance({ actorId: viewer.userId, confirmed: payload.confirmed === true, reason: payload.reason ?? "", }); return Response.json({ retention }); } catch (error) { return apiError(error); } }