39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { getCloudViewer } from "@/app/cloud-auth";
|
|
import { beginRelayPurge } from "@/db/relay-purges";
|
|
import { apiError, readJsonMutation } from "../../respond";
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const viewer = await getCloudViewer();
|
|
if (!viewer) {
|
|
return Response.json(
|
|
{ error_code: "authentication_required", message: "请先登录", retryable: false },
|
|
{ status: 401 },
|
|
);
|
|
}
|
|
if (!viewer.isAdmin) {
|
|
return Response.json(
|
|
{ error_code: "forbidden", message: "没有永久删除租户数据的权限", retryable: false },
|
|
{ status: 403 },
|
|
);
|
|
}
|
|
const payload = await readJsonMutation<{
|
|
deletion_request_id?: string;
|
|
reason?: string;
|
|
confirmation?: string;
|
|
}>(request);
|
|
const purge = await beginRelayPurge({
|
|
deletionRequestId: payload.deletion_request_id ?? "",
|
|
actorId: viewer.userId,
|
|
reason: payload.reason ?? "",
|
|
confirmation: payload.confirmation ?? "",
|
|
});
|
|
return Response.json(
|
|
{ purge_id: purge.id, state: purge.state, started_at: purge.started_at },
|
|
{ status: 202, headers: { "cache-control": "no-store" } },
|
|
);
|
|
} catch (error) {
|
|
return apiError(error);
|
|
}
|
|
}
|