45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { createSupabaseRouteClient } from "@/lib/supabase/server";
|
|
|
|
export async function POST(request: Request) {
|
|
const supabase = await createSupabaseRouteClient();
|
|
const {
|
|
data: { session },
|
|
} = await supabase.auth.getSession();
|
|
|
|
if (!session) {
|
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
|
}
|
|
|
|
const { assetId } = (await request.json()) as { assetId?: string };
|
|
if (!assetId) {
|
|
return NextResponse.json({ error: "缺少 assetId" }, { status: 400 });
|
|
}
|
|
|
|
const { error } = await supabase
|
|
.from("media_assets")
|
|
.update({ ocr_status: "processing" })
|
|
.eq("id", assetId)
|
|
.is("deleted_at", null)
|
|
.limit(1);
|
|
|
|
if (error) {
|
|
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
}
|
|
|
|
const backendUrl = process.env.BACKEND_URL ?? process.env.NEXT_PUBLIC_BACKEND_URL;
|
|
if (backendUrl) {
|
|
void fetch(`${backendUrl}/api/v1/tasks/media-ocr`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ asset_id: assetId }),
|
|
}).catch((err) => {
|
|
console.warn("触发后端 OCR 失败", err);
|
|
});
|
|
}
|
|
|
|
return NextResponse.json({ ok: true });
|
|
}
|