import { getCloudViewer } from "@/app/cloud-auth"; import { createFeedback, 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 }, ); } const payload = await readJsonMutation<{ category?: string; message?: string; idempotencyKey?: string; }>(request); const account = await getOrCreateAccount(viewer); const feedback = await createFeedback({ accountId: account.id, actorId: viewer.userId, category: payload.category ?? "", message: payload.message ?? "", idempotencyKey: payload.idempotencyKey ?? "", }); return Response.json({ feedback }, { status: 201 }); } catch (error) { return apiError(error); } }