38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { getCloudViewer } from "@/app/cloud-auth";
|
|
import { resolveFeedback } 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<{
|
|
feedbackId?: string;
|
|
response?: string;
|
|
reason?: string;
|
|
idempotencyKey?: string;
|
|
}>(request);
|
|
const feedback = await resolveFeedback({
|
|
feedbackId: payload.feedbackId ?? "",
|
|
actorId: viewer.userId,
|
|
response: payload.response ?? "",
|
|
reason: payload.reason ?? "",
|
|
idempotencyKey: payload.idempotencyKey ?? "",
|
|
});
|
|
return Response.json({ feedback });
|
|
} catch (error) {
|
|
return apiError(error);
|
|
}
|
|
}
|