/** * /api/captcha/verify — 校验滑块(v2:行为轨迹 + 位置 + 限流)。 * 通过后签发一次性提交令牌(5 分钟、单次消费)。 */ import { NextResponse } from "next/server"; import { verifyCaptcha, type TrackSample } from "@/lib/captcha"; export const runtime = "nodejs"; export async function POST(req: Request) { let body: { challengeId?: number; x?: number; track?: TrackSample[] }; try { body = await req.json(); } catch { return NextResponse.json({ error: "请求格式错误" }, { status: 400 }); } const challengeId = Number(body.challengeId); const x = Number(body.x); const track = body.track; if (!Number.isInteger(challengeId) || !Number.isFinite(x) || !Array.isArray(track)) { return NextResponse.json({ error: "参数错误" }, { status: 400 }); } if (x < -10 || x > 500) { return NextResponse.json({ error: "参数错误" }, { status: 400 }); } const result = verifyCaptcha(req, challengeId, Math.round(x), track); if (!result.ok) { return NextResponse.json({ error: result.error }, { status: 400 }); } return NextResponse.json({ ok: true, submitToken: result.submitToken }); }