29 lines
887 B
TypeScript
29 lines
887 B
TypeScript
import { getCloudViewer } from "@/app/cloud-auth";
|
|
import { getOrCreateAccount, revokeHost } 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 },
|
|
);
|
|
}
|
|
const payload = await readJsonMutation<{ hostId?: string; reason?: string }>(
|
|
request,
|
|
);
|
|
const account = await getOrCreateAccount(viewer);
|
|
const result = await revokeHost({
|
|
accountId: account.id,
|
|
hostId: payload.hostId ?? "",
|
|
actorId: viewer.userId,
|
|
reason: payload.reason ?? "用户从控制台撤销主机",
|
|
});
|
|
return Response.json(result);
|
|
} catch (error) {
|
|
return apiError(error);
|
|
}
|
|
}
|