34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { getCloudViewer } from "@/app/cloud-auth";
|
|
import {
|
|
cancelPairingRequest,
|
|
getOrCreateAccount,
|
|
} 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, headers: { "cache-control": "no-store" } },
|
|
);
|
|
}
|
|
const payload = await readJsonMutation<{ pairingId?: string }>(request);
|
|
const account = await getOrCreateAccount(viewer);
|
|
const result = await cancelPairingRequest({
|
|
accountId: account.id,
|
|
pairingId: payload.pairingId ?? "",
|
|
actorId: viewer.userId,
|
|
});
|
|
return Response.json(result, {
|
|
status: 200,
|
|
headers: { "cache-control": "no-store" },
|
|
});
|
|
} catch (error) {
|
|
const response = apiError(error);
|
|
response.headers.set("cache-control", "no-store");
|
|
return response;
|
|
}
|
|
}
|