Files
douyin-archive/app/api/admin/stt/videos/route.ts
T

49 lines
1.2 KiB
TypeScript

import { NextResponse } from "next/server";
import { getFileUrl } from "@/lib/minio";
import { prisma } from "@/lib/prisma";
import { transcriptionState } from "@/lib/stt/types";
export async function GET() {
try {
const videos = await prisma.video.findMany({
orderBy: { created_at: "desc" },
include: {
author: {
select: {
nickname: true,
},
},
transcriptionTask: true,
transcript: {
select: {
id: true,
transcript: true,
},
},
},
});
const formattedVideos = videos.map((v) => ({
aweme_id: v.aweme_id,
desc: v.desc,
cover_url: v.cover_url ? getFileUrl(v.cover_url) : "",
duration_ms: v.duration_ms,
author: {
nickname: v.author.nickname,
},
transcription: transcriptionState(v.transcript, v.transcriptionTask),
}));
return NextResponse.json({
videos: formattedVideos,
total: videos.length,
});
} catch (error) {
console.error("Failed to fetch videos:", error);
return NextResponse.json(
{ error: "Failed to fetch videos" },
{ status: 500 },
);
}
}