@@ -38,6 +38,7 @@ interface PlaylistVersion {
|
||||
posterUrl: string | null;
|
||||
fps: number;
|
||||
approvalStatus: string;
|
||||
taskTitle: string;
|
||||
}
|
||||
|
||||
interface PlaylistShot {
|
||||
@@ -315,6 +316,7 @@ function ShotThumbnail({
|
||||
{/* Info */}
|
||||
<div className="flex-1 min-w-0 pt-0.5">
|
||||
<p className="font-mono text-xs font-semibold text-white truncate">{shot.shotCode}</p>
|
||||
<p className="text-[10px] text-zinc-500 truncate">{shot.latestVersion.taskTitle}</p>
|
||||
<div className={cn(
|
||||
"flex items-center gap-1 mt-0.5 text-[10px]",
|
||||
APPROVAL_COLORS[shot.latestVersion.approvalStatus]?.split(" ").find(c => c.startsWith("text-")) ?? "text-zinc-400"
|
||||
|
||||
+37
-12
@@ -13,13 +13,14 @@ export async function GET(req: NextRequest) {
|
||||
return NextResponse.json({ error: "projectId required" }, { status: 400 });
|
||||
}
|
||||
|
||||
// All versions are linked to tasks (taskId), not directly to shots.
|
||||
// We query shots with their tasks, and for each task get the latest version.
|
||||
const shots = await db.shot.findMany({
|
||||
where: {
|
||||
projectId,
|
||||
versions: {
|
||||
tasks: {
|
||||
some: {
|
||||
shotId: { not: null },
|
||||
mimeType: { startsWith: "video/" },
|
||||
versions: { some: { isLatest: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -30,12 +31,14 @@ export async function GET(req: NextRequest) {
|
||||
episode: true,
|
||||
status: true,
|
||||
thumbnailUrl: true,
|
||||
tasks: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
versions: {
|
||||
where: {
|
||||
isLatest: true,
|
||||
mimeType: { startsWith: "video/" },
|
||||
},
|
||||
where: { isLatest: true },
|
||||
take: 1,
|
||||
orderBy: { createdAt: "desc" },
|
||||
select: {
|
||||
id: true,
|
||||
versionNumber: true,
|
||||
@@ -44,22 +47,44 @@ export async function GET(req: NextRequest) {
|
||||
posterUrl: true,
|
||||
fps: true,
|
||||
approvalStatus: true,
|
||||
mimeType: true,
|
||||
createdAt: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Only return shots that actually have a latest video version
|
||||
// For each shot, pick the most recently uploaded latest version across all tasks
|
||||
const playlist = shots
|
||||
.map((shot) => ({
|
||||
.map((shot) => {
|
||||
const versions = shot.tasks
|
||||
.flatMap((t) => t.versions.map((v) => ({ ...v, taskTitle: t.title })))
|
||||
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
||||
|
||||
const latest = versions[0] ?? null;
|
||||
if (!latest) return null;
|
||||
|
||||
return {
|
||||
id: shot.id,
|
||||
shotCode: shot.shotCode,
|
||||
episode: shot.episode,
|
||||
status: shot.status,
|
||||
thumbnailUrl: shot.thumbnailUrl,
|
||||
latestVersion: shot.versions[0] ?? null,
|
||||
}))
|
||||
.filter((shot) => shot.latestVersion !== null);
|
||||
latestVersion: {
|
||||
id: latest.id,
|
||||
versionNumber: latest.versionNumber,
|
||||
fileUrl: latest.fileUrl,
|
||||
thumbnailUrl: latest.thumbnailUrl,
|
||||
posterUrl: latest.posterUrl,
|
||||
fps: latest.fps,
|
||||
approvalStatus: latest.approvalStatus,
|
||||
taskTitle: latest.taskTitle,
|
||||
},
|
||||
};
|
||||
})
|
||||
.filter((s): s is NonNullable<typeof s> => s !== null);
|
||||
|
||||
return NextResponse.json({ shots: playlist });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user