feat(pipeline): render-derived shot thumbnails, and bulk shot delete
Deploy / deploy (push) Failing after 19m11s
Deploy / deploy (push) Failing after 19m11s
Two independent features landing together: Generated shot thumbnails — a shot can now carry a thumbnail promoted from a render export (Shot.generatedThumbnailUrl/generatedThumbnailFrom) alongside the existing brief-supplied thumbnailUrl, which always takes display precedence (lib/shot-thumbnail.ts) so a promoted frame can only ever fill a gap, never overwrite the brief. Shows with pipelineConfig.autoShotThumbnail promote automatically on every finished export (lib/render-pipeline/preview.ts); promoteExportThumbnail/ clearGeneratedThumbnail (actions/shots.ts) are the manual equivalent for everyone else. Worker-side seek logic for picking the promoted frame is covered by RenderWorker/VFXReviewWorker.Tests/ThumbnailSeekTests.cs. Bulk shot delete — the shot-status page's selection bar gets a "Bulk Actions" dropdown (alongside the existing Change Due Date) with Delete Shots. bulkDeleteShots() (actions/shots.ts) deletes one at a time rather than in a single statement: exports_shotId_fkey is ON DELETE RESTRICT by design, so a shot with renders or deliveries on record is protected and gets skipped and reported by name rather than aborting the whole selection or being silently destroyed along with its history. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+142
-1
@@ -4,7 +4,7 @@ import { auth } from "@/auth";
|
||||
import { db } from "@/lib/db";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { z } from "zod";
|
||||
import { ShotStatus, ShotPriority, ShotApprovalStatus } from "@prisma/client";
|
||||
import { ShotStatus, ShotPriority, ShotApprovalStatus, Prisma } from "@prisma/client";
|
||||
import { recalcShotStatus } from "@/lib/shot-status";
|
||||
|
||||
const createShotSchema = z.object({
|
||||
@@ -615,6 +615,59 @@ export async function bulkUpdateDueDates(
|
||||
return { success: true, updated: shots.length };
|
||||
}
|
||||
|
||||
// ── Bulk Delete Shots ─────────────────────────────────────────────────────────
|
||||
|
||||
export async function bulkDeleteShots(shotIds: string[]) {
|
||||
const session = await auth();
|
||||
if (!session?.user) throw new Error("Unauthorized");
|
||||
if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role)) {
|
||||
throw new Error("Insufficient permissions");
|
||||
}
|
||||
|
||||
if (!shotIds.length) return { success: true, deleted: 0, failed: [] as { shotId: string; shotCode: string; reason: string }[] };
|
||||
|
||||
const shots = await db.shot.findMany({
|
||||
where: { id: { in: shotIds } },
|
||||
select: { id: true, shotCode: true, projectId: true },
|
||||
});
|
||||
|
||||
const projectIds = [...new Set(shots.map((s) => s.projectId))];
|
||||
const failed: { shotId: string; shotCode: string; reason: string }[] = [];
|
||||
let deleted = 0;
|
||||
|
||||
// One at a time, not deleteMany: a shot with renders or deliveries is
|
||||
// protected at the database level (exports_shotId_fkey is ON DELETE
|
||||
// RESTRICT, deliberately — delivery history must never be destroyable by
|
||||
// deleting the shot underneath it). A single bulk statement would abort
|
||||
// entirely on the first shot it hits; deleting individually means every
|
||||
// shot that *can* go still does, and the ones that can't are reported by
|
||||
// name instead of failing the whole selection.
|
||||
for (const shot of shots) {
|
||||
try {
|
||||
await db.shot.delete({ where: { id: shot.id } });
|
||||
deleted += 1;
|
||||
} catch (e) {
|
||||
failed.push({
|
||||
shotId: shot.id,
|
||||
shotCode: shot.shotCode,
|
||||
reason:
|
||||
e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2003"
|
||||
? "has renders or deliveries — delete those first"
|
||||
: e instanceof Error
|
||||
? e.message
|
||||
: "unknown error",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const pid of projectIds) {
|
||||
revalidatePath(`/projects/${pid}`);
|
||||
}
|
||||
revalidatePath(`/shot-status`);
|
||||
|
||||
return { success: true, deleted, failed };
|
||||
}
|
||||
|
||||
export async function renameFootagePlate(plateId: string, label: string) {
|
||||
const session = await auth();
|
||||
if (!session?.user) throw new Error("Unauthorized");
|
||||
@@ -1213,3 +1266,91 @@ export async function updateShotVersion(shotId: string, version: string) {
|
||||
revalidatePath(`/projects/${shot.projectId}/shots/${shotId}`);
|
||||
return { success: true, shotVersion: version };
|
||||
}
|
||||
|
||||
// ── Generated (render-derived) shot thumbnails ───────────────────────────────
|
||||
//
|
||||
// A shot can carry two stills: `thumbnailUrl`, the reference frame that came
|
||||
// with the brief, and `generatedThumbnailUrl`, a frame promoted from a render
|
||||
// export. The reference always wins on display (lib/shot-thumbnail.ts), so
|
||||
// these actions can only ever fill a gap — a promotion never overwrites the
|
||||
// brief, and clearing one always falls back to it.
|
||||
//
|
||||
// Shows with `pipelineConfig.autoShotThumbnail` promote on every finished
|
||||
// export automatically (lib/render-pipeline/preview.ts). These actions are the
|
||||
// manual equivalent, and work regardless of that flag: a supervisor can pull a
|
||||
// frame onto one shot on a project that is otherwise hands-off.
|
||||
|
||||
/**
|
||||
* Promote a render export's thumbnail onto its shot.
|
||||
*
|
||||
* With no `exportId`, uses the newest export of that shot which actually has a
|
||||
* thumbnail — "use the latest render frame".
|
||||
*/
|
||||
export async function promoteExportThumbnail(shotId: string, exportId?: string) {
|
||||
const session = await auth();
|
||||
if (!session?.user) throw new Error("Unauthorized");
|
||||
if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role)) {
|
||||
throw new Error("Insufficient permissions");
|
||||
}
|
||||
|
||||
const shot = await db.shot.findUnique({
|
||||
where: { id: shotId },
|
||||
select: { id: true, projectId: true },
|
||||
});
|
||||
if (!shot) throw new Error("Shot not found");
|
||||
|
||||
const exportRow = await db.export.findFirst({
|
||||
where: {
|
||||
shotId,
|
||||
thumbnailKey: { not: null },
|
||||
...(exportId ? { id: exportId } : {}),
|
||||
},
|
||||
orderBy: { versionNumber: "desc" },
|
||||
select: { id: true, thumbnailKey: true, versionString: true },
|
||||
});
|
||||
if (!exportRow?.thumbnailKey) {
|
||||
throw new Error(
|
||||
exportId
|
||||
? "That export has no thumbnail — its preview may have been skipped, or the worker had no ffmpeg configured"
|
||||
: "No render of this shot has produced a thumbnail yet"
|
||||
);
|
||||
}
|
||||
|
||||
const generatedThumbnailUrl = `/api/files/${exportRow.thumbnailKey}`;
|
||||
await db.shot.update({
|
||||
where: { id: shotId },
|
||||
data: { generatedThumbnailUrl, generatedThumbnailFrom: exportRow.versionString },
|
||||
});
|
||||
|
||||
revalidatePath(`/projects/${shot.projectId}`);
|
||||
revalidatePath(`/projects/${shot.projectId}/shots/${shotId}`);
|
||||
return {
|
||||
success: true,
|
||||
generatedThumbnailUrl,
|
||||
generatedThumbnailFrom: exportRow.versionString,
|
||||
};
|
||||
}
|
||||
|
||||
/** Drop the render-derived still. The reference frame, if any, comes back. */
|
||||
export async function clearGeneratedThumbnail(shotId: string) {
|
||||
const session = await auth();
|
||||
if (!session?.user) throw new Error("Unauthorized");
|
||||
if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role)) {
|
||||
throw new Error("Insufficient permissions");
|
||||
}
|
||||
|
||||
const shot = await db.shot.findUnique({
|
||||
where: { id: shotId },
|
||||
select: { id: true, projectId: true },
|
||||
});
|
||||
if (!shot) throw new Error("Shot not found");
|
||||
|
||||
await db.shot.update({
|
||||
where: { id: shotId },
|
||||
data: { generatedThumbnailUrl: null, generatedThumbnailFrom: null },
|
||||
});
|
||||
|
||||
revalidatePath(`/projects/${shot.projectId}`);
|
||||
revalidatePath(`/projects/${shot.projectId}/shots/${shotId}`);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user