This commit is contained in:
eric
2026-03-30 10:36:08 -05:00
parent 2307411b37
commit 2ffbddff2e
8 changed files with 454 additions and 6 deletions

View File

@@ -27,6 +27,7 @@ async function registerOrLoginUser(
email,
password,
passwordConfirm: password,
live_allowed: true,
}),
cache: "no-store",
}).catch(() => null);

View File

@@ -33,6 +33,7 @@ async function ensurePbUserExists(pbUrl: string, email: string): Promise<void> {
email,
password: DEFAULT_PASSWORD,
passwordConfirm: DEFAULT_PASSWORD,
live_allowed: true,
}),
});
if (registerRes.ok) {

View File

@@ -0,0 +1,52 @@
import { NextRequest, NextResponse } from "next/server";
import { getApiUrlFromRequest, getPaymentConfig } from "@/config/services.config";
function resolvePayApiUrl(request: NextRequest): string {
const hostHeader =
request.headers.get("host") || request.headers.get("x-forwarded-host");
return (
(hostHeader ? getApiUrlFromRequest(hostHeader) : null) ||
getPaymentConfig().apiUrl
).replace(/\/$/, "");
}
export async function POST(request: NextRequest) {
try {
const formData = await request.formData();
const image = formData.get("image");
if (!(image instanceof File)) {
return NextResponse.json(
{ ok: false, error: "缺少图片文件 image" },
{ status: 400 }
);
}
const payload = new FormData();
payload.append("image", image, image.name || "proof.jpg");
const apiUrl = resolvePayApiUrl(request);
const res = await fetch(`${apiUrl}/nomadvip/recognize_discount_proof`, {
method: "POST",
body: payload,
cache: "no-store",
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
return NextResponse.json(
{ ok: false, error: data?.error || "识别服务异常" },
{ status: res.status }
);
}
return NextResponse.json(data);
} catch (error) {
return NextResponse.json(
{
ok: false,
error: error instanceof Error ? error.message : "识别请求失败",
},
{ status: 500 }
);
}
}