feat: add manual video tagging
This commit is contained in:
+36
-1
@@ -3,6 +3,30 @@ export const runtime = "nodejs";
|
||||
import { type NextRequest, NextResponse } from "next/server";
|
||||
import { transcriptAweme } from ".";
|
||||
|
||||
const runningJobs = new Map<string, Promise<void>>();
|
||||
|
||||
function startBackgroundAsr(awemeId: string) {
|
||||
if (runningJobs.has(awemeId)) return false;
|
||||
|
||||
const job = transcriptAweme(awemeId, {
|
||||
log: (message) => console.log(`[ASR ${awemeId}] ${message}`),
|
||||
})
|
||||
.then((result) => {
|
||||
console.log(
|
||||
`[ASR ${awemeId}] done tags=${result.content_tags.join("、")}`,
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`[ASR ${awemeId}] failed:`, error);
|
||||
})
|
||||
.finally(() => {
|
||||
runningJobs.delete(awemeId);
|
||||
});
|
||||
|
||||
runningJobs.set(awemeId, job);
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const awemeId = searchParams.get("awemeId");
|
||||
@@ -12,8 +36,19 @@ export async function GET(req: NextRequest) {
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
const asyncMode =
|
||||
searchParams.get("async") === "1" || searchParams.get("mode") === "async";
|
||||
|
||||
if (asyncMode) {
|
||||
const started = startBackgroundAsr(awemeId);
|
||||
return NextResponse.json(
|
||||
{ awemeId, status: started ? "started" : "running" },
|
||||
{ status: 202 },
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await transcriptAweme(awemeId, /* {log: (msg) => console.log(`[ASR] ${msg}`)} */);
|
||||
const result = await transcriptAweme(awemeId);
|
||||
return NextResponse.json(result);
|
||||
} catch (error) {
|
||||
console.error("ASR failed:", error);
|
||||
|
||||
Reference in New Issue
Block a user