This commit is contained in:
eric
2026-03-15 04:25:45 -05:00
parent df12c7af4a
commit bbaa38b3b3
32 changed files with 4312 additions and 152 deletions

View File

@@ -0,0 +1,44 @@
import { NextRequest, NextResponse } from "next/server";
import { getApiUrlFromRequest, getPaymentConfig } from "@/config/services.config";
function resolvePayApiUrl(request: NextRequest): string {
const payConfig = getPaymentConfig();
const hostHeader = request.headers.get("host") || request.headers.get("x-forwarded-host");
return ((hostHeader ? getApiUrlFromRequest(hostHeader) : null) || payConfig.apiUrl).replace(/\/$/, "");
}
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params;
const body = await request.json().catch(() => ({}));
const user_id = String(body?.user_id ?? body?.userId ?? "").trim();
const reaction_type = String(body?.reaction_type ?? "UPVOTE").trim();
if (!user_id) {
return NextResponse.json({ ok: false, error: "缺少 user_id" }, { status: 401 });
}
try {
const apiUrl = resolvePayApiUrl(request);
const res = await fetch(`${apiUrl}/community/memos/${encodeURIComponent(id)}/reactions`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ user_id, reaction_type }),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
return NextResponse.json(
{ ok: false, error: data?.detail || "点赞失败" },
{ status: res.status }
);
}
return NextResponse.json(data);
} catch (error) {
console.error("[community/reactions] POST error:", error);
return NextResponse.json({ ok: false, error: "服务异常" }, { status: 500 });
}
}