35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { AdminAuthorizationError } from "@/lib/admin/auth";
|
|
import { adminErrorResponse, requireAdminMutation } from "@/lib/admin/http";
|
|
import { epaySubmitUrl, readEpayConfig } from "@/lib/epay/config";
|
|
import { probePublicEpayGateway } from "@/lib/epay/gateway-policy";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
function reachableStatus(status: number) {
|
|
return status >= 200 && status < 500;
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
await requireAdminMutation(request, "billing.adjustments.write");
|
|
const config = await readEpayConfig();
|
|
const submitUrl = epaySubmitUrl(config.gatewayUrl);
|
|
const startedAt = performance.now();
|
|
const status = await probePublicEpayGateway(submitUrl);
|
|
const available = reachableStatus(status);
|
|
return NextResponse.json({
|
|
available,
|
|
message: available ? "当前已保存的易支付配置可访问" : "当前已保存的易支付配置暂不可用",
|
|
latencyMs: Math.round(performance.now() - startedAt),
|
|
status,
|
|
});
|
|
} catch (error) {
|
|
if (error instanceof AdminAuthorizationError) return adminErrorResponse(error);
|
|
return NextResponse.json({
|
|
available: false,
|
|
message: "当前已保存的易支付配置暂不可用",
|
|
});
|
|
}
|
|
}
|