Your Name c1b03278ca
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
Harden public attack surface
2026-05-23 11:36:02 +08:00

47 lines
1.1 KiB
TypeScript

import { NextResponse } from "next/server";
import { auth } from "@/app/(auth)/auth";
export const runtime = "nodejs";
export const maxDuration = 10;
export async function POST(request: Request) {
try {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json(
{
success: false,
data: null,
error: "未授权,请先登录",
},
{ status: 401 }
);
}
const body = await request.json();
// 转发到 Florence-2 后端(本地服务)
const response = await fetch("http://localhost:8002/api/detect-object", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
const data = await response.json();
return NextResponse.json(data);
} catch (error) {
console.error("Florence API proxy error:", error);
return NextResponse.json(
{
success: false,
data: null,
error: `代理错误: ${error instanceof Error ? error.message : "未知错误"}`,
},
{ status: 500 }
);
}
}