feat: establish NekoNest Cloud control and relay
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user