3 Commits

Author SHA1 Message Date
twotalesanimation 0ce41123c5 feat(render-pipeline): regenerate previews without re-rendering EXRs
Deploy / deploy (push) Successful in 5m58s
A slate or burn-in mistake is usually caught after a preview has already
succeeded, and there was no way back: retryPreview required PREVIEW_FAILED, and
READY_FOR_QC only led on to QC_FAILED/READY_FOR_DELIVERY/SUPERSEDED. The only
recourse was a whole new export, re-rendering every EXR and burning a version
number to fix a typo.

- transitions: READY_FOR_QC and QC_FAILED can now go back to GENERATING_PREVIEW.
- regeneratePreview() rebuilds the manifest from scratch rather than patching
  anything, so shot code, episode/scene, frame count, slate date and burn-ins
  are all re-derived exactly as on a first-time preview. Validated EXRs are
  reused and the version number is untouched -- this re-delivers the same
  version, it does not make a new one.
- vfxScope and submissionNote are frozen onto the Export at submission time, so
  regenerating refreshes that snapshot from the shot's slate fields (explicit
  override wins, same precedence as createExport). Slate text edited on the web
  app's Slate tab is therefore picked up.
- finalizePreview replaces the media on the export's existing Version instead of
  stacking a second row, so the version number stays put and reviewer notes and
  annotations survive the reslate. First-time previews are unaffected.
- POST /api/ext/exports/{id}/regenerate-preview exposes it to the panel.
- Panel: Regenerate Previews button, gated on the same statuses as the server,
  with a confirm covering what is and is not reused.

Also fixes the slate description source: the Slate tab authors
shot.slateDescription (falling back to shot.description) but the preview
manifest only ever read shot.description, so edits made there never reached the
rendered slate.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-12 11:02:23 +02:00
twotalesanimation 783e82eaf5 feat(render-pipeline): sync task title to preview version, fill slate ShotName
finalizePreview now retitles the export's task so its version suffix matches the
preview that was just uploaded (UNG_102_019_010_cmp_TT_v004 -> _v005), which is
the rename the manual batch upload already does on rename-and-upload. The new
nextTaskTitle helper mirrors nextExrOutputBase so the task title, EXR base and
preview filename all derive the suffix the same way. It uses the export's
versionString rather than versionNumber, since the DB number is bumped to stay
monotonic per task while the filename follows the shot's shotVersion.

The rename only fires when a Version was actually created, runs in the same
transaction, and is recorded in the ExportEvent note; the finalize response now
returns the task id, title and whether it changed. Task status is deliberately
untouched (pipeline renders must not resurface in the review flow, S10.0).

The headless preview build was addressing the slate's identity fields by index
only, so ShotName was never filled on the farm. setSlateIdentity writes both the
named property and the index -- the name-with-index-fallback pattern the panel
already uses for VersionName -- and warns with the template's actual property
names when neither resolves, instead of failing silently.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-12 10:30:47 +02:00
twotalesanimation c4abda2d63 feat(connector): per-shot/version export folders, scene filter
Panel export paths now mirror the server's layout
({exportRoot}/{showId}/[{episode} if episodic]/{shotCode}/{version}) via a new
getShotExportDir helper, so farm and local renders land in the same folder.
Folder creation moves into the per-shot loop so one unwritable path no longer
aborts the whole queue.

Also adds an optional `scene` query param to the ext shots endpoint.
2026-08-12 10:29:51 +02:00
7 changed files with 415 additions and 52 deletions
+27 -4
View File
@@ -230,6 +230,26 @@
return names;
}
// Slate identity fields (version name, shot name). Current templates expose
// these under a stable name, older ones only positionally, and the two do
// not always line up — so write both. Setting the same property twice is
// harmless; the panel uses the same name-with-index-fallback pattern.
function setSlateIdentity(layer, propName, index, value, label) {
var byName;
var byIndex;
if (value === null || value === undefined || value === "") {
return; // leave the template's own default
}
byName = setEssentialProperty(layer, propName, value);
byIndex = setEssentialPropertyByIndex(layer, index, value);
if (!byName && !byIndex) {
warn(label + ": neither Essential Property \"" + propName + "\" nor index " +
index + " could be set. Available: " +
listEssentialPropertyNames(layer).join(", "));
}
}
// Per-submission fields (VFX Scope / Submission Note). The property names
// come from config; if one does not exist, report the template's actual
// property names so it can be corrected without another build.
@@ -439,12 +459,15 @@
var slateLayer = previewComp.layer("NETFLIX_SLATE");
if (slateLayer) {
// Index-addressed properties match the panel exactly (3 = version
// name, 10 = shot code); the rest are addressed by name.
setEssentialPropertyByIndex(slateLayer, 3, ctx.slate.versionName);
// Identity fields match the panel's indices (3 = version name,
// 10 = shot name) and are also written by name; the rest are
// addressed by name only.
// VersionName carries the full "{shotCode}_cmp_TT_{version}";
// ShotName is the bare shot code, with no version suffix.
setSlateIdentity(slateLayer, "VersionName", 3, ctx.slate.versionName, "Version Name");
setSlateIdentity(slateLayer, "ShotName", 10, ctx.slate.shotCode, "Shot Name");
setEssentialProperty(slateLayer, "Date", ctx.slate.date);
setEssentialProperty(slateLayer, "Desc", ctx.slate.description);
setEssentialPropertyByIndex(slateLayer, 10, ctx.slate.shotCode);
setEssentialProperty(slateLayer, "Episode", ctx.slate.episode);
setEssentialProperty(slateLayer, "Scene", ctx.slate.scene);
setEssentialProperty(slateLayer, "Frames", result.frameCount);
+104 -11
View File
@@ -315,6 +315,27 @@ var SETTINGS_KEY = "cfg";
return CONFIG.footageRoot + (showId ? "/" + showId : "");
}
// Mirrors the server's export layout so farm and local renders land together:
// {exportRoot}/{showId}/[{episode} for episodic]/{shotCode}/{version}
function getShotExportDir(shot) {
var path = getShowExportRoot();
var episode;
var match;
if (CURRENT_PROJECT && CURRENT_PROJECT.projectType === "EPISODIC") {
episode = trimText(shot.episode);
if (!episode) {
match = String(shot.shotCode).match(/^[A-Z]{3}_(\d{3})_/);
episode = match ? match[1] : "";
}
if (episode) {
path += "/" + episode;
}
}
return path + "/" + shot.shotCode + "/" + (shot.shotVersion || "v001");
}
function ensureFolder(path) {
var folder = new Folder(path);
var parent;
@@ -912,7 +933,7 @@ var SETTINGS_KEY = "cfg";
disableLayerByName(comp, "UNG_VFX_OVERLAY");
disableLayerByName(comp, "_SHOW LUT");
folderPath = getShowExportRoot() + "/" + shotCode;
folderPath = getShotExportDir(shot);
if (!ensureFolder(folderPath)) {
addFailure(result, comp.name, "Could not create output folder");
continue;
@@ -1242,14 +1263,9 @@ var SETTINGS_KEY = "cfg";
var mainComp;
var previewComp;
var outputPath;
var folderPath;
app.beginUndoGroup("VFXReview Connector - Queue " + label);
if (!ensureFolder(getShowExportRoot())) {
app.endUndoGroup();
updateStatus(comps.length, "Could not create export folder.");
return;
}
for (i = 0; i < comps.length; i += 1) {
shotCode = getShotCodeFromComp(comps[i]);
updateStatus(comps.length, "Preparing " + label + " preview for " + shotCode + " (" + (i + 1) + " of " + comps.length + ")");
@@ -1282,7 +1298,13 @@ var SETTINGS_KEY = "cfg";
}
updateStatus(comps.length, "Queueing " + label + " for " + shotCode + " (" + (i + 1) + " of " + comps.length + ")");
outputPath = getShowExportRoot() + "/" + shotCode + "_cmp_TT_" + (apiData.shot.shotVersion || "v001") + "." + extension;
folderPath = getShotExportDir(apiData.shot);
if (!ensureFolder(folderPath)) {
addFailure(result, comps[i].name, "Could not create output folder");
continue;
}
outputPath = folderPath + "/" + shotCode + "_cmp_TT_" + (apiData.shot.shotVersion || "v001") + "." + extension;
if (queueCompWithOutput(previewComp, templateName, outputPath)) {
queued += 1;
result.queued += 1;
@@ -1323,7 +1345,7 @@ var SETTINGS_KEY = "cfg";
disableLayerByName(comp, "UNG_VFX_OVERLAY");
disableLayerByName(comp, "_SHOW LUT");
folderPath = getShowExportRoot() + "/" + shotCode;
folderPath = getShotExportDir(shot);
if (!ensureFolder(folderPath)) {
addFailure(result, comp.name, "Could not create output folder");
continue;
@@ -1384,7 +1406,7 @@ var SETTINGS_KEY = "cfg";
continue;
}
exportFolder = new Folder(getShowExportRoot() + "/" + shot.shotCode);
exportFolder = new Folder(getShotExportDir(shot));
if (!exportFolder.exists) {
updateStatus(comps.length, "Export folder not found: " + exportFolder.fsName);
skipped += 1;
@@ -1596,7 +1618,7 @@ var SETTINGS_KEY = "cfg";
expectedBaseName = shotCode + "_cmp_TT_" + (shot.shotVersion || "v001");
exrOutputBase = shot.exrOutput || "";
sourceFolder = new Folder(getShowExportRoot() + "/" + shotCode);
sourceFolder = new Folder(getShotExportDir(shot));
if (!sourceFolder.exists) {
addFailure(result, comp.name, "Source export folder not found: " + sourceFolder.fsName);
continue;
@@ -2505,6 +2527,13 @@ var SETTINGS_KEY = "cfg";
status === "VALIDATING" || status === "GENERATING_PREVIEW";
}
// Mirrors REGENERATABLE_STATUSES on the server: every state where the EXRs
// are known good, so only the preview needs rebuilding.
function isRegeneratableExportStatus(status) {
return status === "READY_FOR_QC" || status === "QC_FAILED" ||
status === "PREVIEW_FAILED";
}
function formatEtaShort(seconds) {
var mins;
var secs;
@@ -2836,6 +2865,57 @@ var SETTINGS_KEY = "cfg";
}
}
// Rebuild the delivered MOV/MP4 after a slate/burn-in mistake: same version,
// same EXRs, freshly built slate. Slate text (description, scope, note)
// comes from the shot record, so it is fixed on the web app first — except
// the panel's Sub. Note field, which still wins as a per-export override.
function regenerateLatestPreview() {
var shotCode = getStatusShotCode();
var data;
var exportInfo;
var body = {};
var note;
var response;
if (!shotCode) {
setPipelineStatus("Select a comp or shot first");
return;
}
data = getLatestExportData(shotCode);
exportInfo = data ? data.export : null;
if (!exportInfo) {
setPipelineStatus(shotCode + " — no export to regenerate");
return;
}
if (!isRegeneratableExportStatus(String(exportInfo.status))) {
setPipelineStatus(formatExportStatus(shotCode, exportInfo) +
" — preview can only be regenerated once the render is done");
return;
}
if (!confirm("Rebuild the preview for " + shotCode + " " + exportInfo.versionString + "?\n\n" +
"The rendered EXRs are reused and the version number stays the same.\n" +
"The existing review version's media is replaced.")) {
return;
}
if (uiState.submissionNoteField) {
note = trimText(uiState.submissionNoteField.text);
if (note) {
body.submissionNote = note;
}
}
setPipelineStatus(shotCode + " " + exportInfo.versionString + " — regenerating preview...");
response = postJSON(CONFIG.baseUrl + "/api/ext/exports/" + exportInfo.id + "/regenerate-preview", body);
if (response.status === 200) {
setPipelineStatus(shotCode + " " + exportInfo.versionString + " — preview queued");
startExportPolling(shotCode);
} else {
setPipelineStatus("Regenerate failed: " +
((response.data && response.data.error) ? response.data.error : "HTTP " + response.status));
}
}
function buildUI(thisObjRef) {
var win = (thisObjRef instanceof Panel) ? thisObjRef : new Window("palette", "VFXReview Connector", undefined, { resizeable: true });
var bannerFile;
@@ -2847,9 +2927,11 @@ var SETTINGS_KEY = "cfg";
var pipelinePanel;
var pipelineRow1;
var pipelineRow2;
var pipelineRow3;
var queueExportButton;
var refreshExportButton;
var retryExportButton;
var regeneratePreviewButton;
var buttonsPanel;
var btnRow1;
var btnRow2;
@@ -2984,6 +3066,16 @@ var SETTINGS_KEY = "cfg";
refreshExportButton = pipelineRow2.add("button", undefined, "Refresh Status");
retryExportButton = pipelineRow2.add("button", undefined, "Retry Export");
pipelineRow3 = pipelinePanel.add("group");
pipelineRow3.orientation = "row";
pipelineRow3.alignChildren = ["fill", "center"];
pipelineRow3.spacing = 6;
regeneratePreviewButton = pipelineRow3.add("button", undefined, "Regenerate Previews");
regeneratePreviewButton.helpTip =
"Rebuild the MOV/MP4 slate and burn-ins for the delivered version.\n" +
"Reuses the rendered EXRs and keeps the version number. Slate text is\n" +
"re-read from the shot, so fix it on the web app's Slate tab first.";
buttonsPanel = scrollContent.add("panel", undefined, "Actions");
buttonsPanel.orientation = "column";
buttonsPanel.alignChildren = ["fill", "top"];
@@ -3100,6 +3192,7 @@ var SETTINGS_KEY = "cfg";
queueExportButton.onClick = queueExport;
refreshExportButton.onClick = refreshExportStatus;
retryExportButton.onClick = retryLatestExport;
regeneratePreviewButton.onClick = regenerateLatestPreview;
refreshButton.onClick = refreshSelection;
fixNamesButton.onClick = fixCompNames;
overlayButton.onClick = addOverlay;
@@ -0,0 +1,49 @@
import { NextRequest, NextResponse } from "next/server";
import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth";
import { toErrorResponse } from "@/lib/render-pipeline/errors";
import { regeneratePreview } from "@/lib/render-pipeline/preview";
// ── POST /api/ext/exports/{exportId}/regenerate-preview (E15b) ───────────────
//
// Rebuild the preview MOV/MP4 for an export that already delivered one, after a
// slate or burn-in mistake was caught. Reuses the validated EXRs and keeps the
// version number; slate text edited on the web app's Slate tab is picked up.
//
// Body (all optional):
// vfxScope per-export override; omit to re-read the shot's slate field
// submissionNote same
// note audit note for the ExportEvent
export async function POST(
req: NextRequest,
{ params }: { params: Promise<{ exportId: string }> }
) {
if (!isExtAuthorized(req)) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { exportId } = await params;
let body: {
vfxScope?: string | null;
submissionNote?: string | null;
note?: string;
} = {};
try {
const parsed = await req.json();
if (parsed && typeof parsed === "object") body = parsed;
} catch {
// empty body is fine — everything falls back to the shot's slate fields
}
try {
const result = await regeneratePreview(exportId, {
...(body.vfxScope !== undefined ? { vfxScope: body.vfxScope } : {}),
...(body.submissionNote !== undefined ? { submissionNote: body.submissionNote } : {}),
note: typeof body.note === "string" ? body.note : "Regenerate preview from AE panel",
});
return NextResponse.json(result);
} catch (err) {
const { body: errBody, status } = toErrorResponse(err);
return NextResponse.json(errBody, { status });
}
}
@@ -18,6 +18,7 @@ function isAuthorized(req: NextRequest): boolean {
//
// Query params (all optional):
// episode e.g. 108
// scene e.g. 022
// sequence e.g. 004
// status e.g. IN_PROGRESS
// page (default 1)
@@ -60,6 +61,7 @@ export async function GET(
where: {
projectId: project.id,
...(episode ? { episode } : {}),
...(scene ? { scene } : {}),
...(sequence ? { sequence } : {}),
...(status ? { status: status as never } : {}),
},
+32
View File
@@ -0,0 +1,32 @@
import { describe, it, expect } from "vitest";
import { nextTaskTitle } from "./preview";
describe("nextTaskTitle", () => {
it("swaps an existing version suffix", () => {
expect(nextTaskTitle("UNG_102_019_010_cmp_TT_v004", "v005")).toBe(
"UNG_102_019_010_cmp_TT_v005"
);
});
it("is idempotent when the title already matches", () => {
expect(nextTaskTitle("UNG_102_019_010_cmp_TT_v005", "v005")).toBe(
"UNG_102_019_010_cmp_TT_v005"
);
});
it("appends when the title carries no version yet", () => {
expect(nextTaskTitle("UNG_102_019_010_cmp_TT", "v005")).toBe(
"UNG_102_019_010_cmp_TT_v005"
);
});
it("only touches a trailing suffix, not a version inside the name", () => {
expect(nextTaskTitle("UNG_v001_019_010_cmp_TT_v004", "v005")).toBe(
"UNG_v001_019_010_cmp_TT_v005"
);
});
it("handles double-digit and uppercase suffixes", () => {
expect(nextTaskTitle("SHOT_cmp_TT_V12", "v013")).toBe("SHOT_cmp_TT_v013");
});
});
+196 -35
View File
@@ -1,4 +1,4 @@
import { Prisma } from "@prisma/client";
import { ExportStatus, Prisma } from "@prisma/client";
import { db } from "@/lib/db";
import { PipelineError } from "./errors";
import { applyTransition } from "./transitions";
@@ -68,7 +68,14 @@ type ExportForPreview = {
export async function buildPreviewManifest(exportRow: ExportForPreview): Promise<PreviewManifest> {
const shot = await db.shot.findUnique({
where: { id: exportRow.shotId },
select: { shotCode: true, episode: true, scene: true, description: true, notes: true },
select: {
shotCode: true,
episode: true,
scene: true,
description: true,
notes: true,
slateDescription: true,
},
});
if (!shot) throw new PipelineError(404, "Shot not found for export");
@@ -98,7 +105,10 @@ export async function buildPreviewManifest(exportRow: ExportForPreview): Promise
slate: {
versionName: base,
date: slateDate(),
description: shot.description,
// The slate's own description is authored on the Shot's Slate tab and
// falls back to the general shot description — the same precedence the
// tab shows as its placeholder.
description: shot.slateDescription ?? shot.description,
notes: shot.notes,
shotCode: shot.shotCode,
episode: shot.episode,
@@ -129,6 +139,16 @@ export async function createPreviewJob(
});
}
/**
* `UNG_102_019_010_cmp_TT_v004` + v005 → `UNG_102_019_010_cmp_TT_v005`.
* Mirrors `nextExrOutputBase` (exports.ts) so the task title, the EXR base and
* the preview filename all carry the same version suffix.
*/
export function nextTaskTitle(current: string, versionString: string): string {
if (/_v\d+$/i.test(current)) return current.replace(/_v\d+$/i, `_${versionString}`);
return `${current}_${versionString}`;
}
export interface FinalizeInput {
artifacts?: {
deliveryMovPath?: string;
@@ -167,6 +187,7 @@ export async function finalizePreview(jobId: string, machineId: string, body: Fi
return {
export: { id: exportRow.id, status: exportRow.status },
version: { id: exportRow.versionId },
task: null,
alreadyApplied: true,
};
}
@@ -186,45 +207,90 @@ export async function finalizePreview(jobId: string, machineId: string, body: Fi
});
let versionId: string | null = null;
let versionReplaced = false;
if (artifacts.previewMovKey) {
// Version numbering stays monotonic for the task (existing review flows
// rely on the newest version having the highest number) while matching
// the export version whenever it is ahead.
const taskMax = exportRow.taskId
? await tx.version.aggregate({
where: { taskId: exportRow.taskId },
_max: { versionNumber: true },
})
: { _max: { versionNumber: null as number | null } };
const versionNumber = Math.max((taskMax._max.versionNumber ?? 0) + 1, exportRow.versionNumber);
const mediaFields = {
fileUrl: `/api/files/${artifacts.previewMovKey}`,
fileName: media.fileName ?? `${exportRow.versionString}.mp4`,
mimeType: "video/mp4",
thumbnailUrl: artifacts.thumbnailKey ? `/api/files/${artifacts.thumbnailKey}` : undefined,
fps: media.fps ?? exportRow.fps,
frameCount: media.frameCount ?? exportRow.frameEnd - exportRow.frameStart + 1,
width: media.width ?? exportRow.width,
height: media.height ?? exportRow.height,
};
// Regenerating a preview (T11b) re-delivers the *same* export version, so
// it replaces the media on the Version already registered rather than
// stacking a second row: the version number stays put and any notes or
// annotations reviewers left on it survive the reslate.
const existing = exportRow.versionId
? await tx.version.findUnique({ where: { id: exportRow.versionId }, select: { id: true } })
: null;
if (existing) {
await tx.version.update({
where: { id: existing.id },
data: { ...mediaFields, isLatest: true },
});
versionId = existing.id;
versionReplaced = true;
} else {
// Version numbering stays monotonic for the task (existing review flows
// rely on the newest version having the highest number) while matching
// the export version whenever it is ahead.
const taskMax = exportRow.taskId
? await tx.version.aggregate({
where: { taskId: exportRow.taskId },
_max: { versionNumber: true },
})
: { _max: { versionNumber: null as number | null } };
const versionNumber = Math.max((taskMax._max.versionNumber ?? 0) + 1, exportRow.versionNumber);
const version = await tx.version.create({
data: {
...mediaFields,
versionNumber,
shotId: exportRow.shotId,
taskId: exportRow.taskId,
artistId: exportRow.submittedById,
notes: `Pipeline render ${exportRow.versionString} (internal only)`,
isLatest: true,
isClientVisible: false, // never shared to the client portal (§10.0)
},
});
versionId = version.id;
}
if (exportRow.taskId) {
await tx.version.updateMany({
where: { taskId: exportRow.taskId },
where: { taskId: exportRow.taskId, id: { not: versionId } },
data: { isLatest: false },
});
}
}
const version = await tx.version.create({
data: {
versionNumber,
shotId: exportRow.shotId,
taskId: exportRow.taskId,
artistId: exportRow.submittedById,
fileUrl: `/api/files/${artifacts.previewMovKey}`,
fileName: media.fileName ?? `${exportRow.versionString}.mp4`,
mimeType: "video/mp4",
thumbnailUrl: artifacts.thumbnailKey ? `/api/files/${artifacts.thumbnailKey}` : undefined,
fps: media.fps ?? exportRow.fps,
frameCount: media.frameCount ?? exportRow.frameEnd - exportRow.frameStart + 1,
width: media.width ?? exportRow.width,
height: media.height ?? exportRow.height,
notes: `Pipeline render ${exportRow.versionString} (internal only)`,
isLatest: true,
isClientVisible: false, // never shared to the client portal (§10.0)
},
// The task title carries the version it is showing (house convention:
// "UNG_102_019_010_cmp_TT_v004"). The preview just uploaded *is* the task's
// new latest version, so the title has to follow the file — the same rename
// the manual batch upload does on "rename-and-upload".
let taskTitle: string | null = null;
let taskRenamed = false;
if (versionId && exportRow.taskId) {
const task = await tx.task.findUnique({
where: { id: exportRow.taskId },
select: { title: true },
});
versionId = version.id;
if (task) {
taskTitle = nextTaskTitle(task.title, exportRow.versionString);
taskRenamed = taskTitle !== task.title;
if (taskRenamed) {
await tx.task.update({
where: { id: exportRow.taskId },
data: { title: taskTitle },
});
}
}
}
const updated = await applyTransition(
@@ -234,7 +300,14 @@ export async function finalizePreview(jobId: string, machineId: string, body: Fi
{
type: "WORKER",
id: machineId,
note: `Preview complete in ${body.renderStats?.previewSeconds ?? "?"}s${versionId ? " — review version created" : " — no preview media reported"}`,
note:
`Preview complete in ${body.renderStats?.previewSeconds ?? "?"}s` +
(versionId
? versionReplaced
? " — review version media replaced"
: " — review version created"
: " — no preview media reported") +
(taskRenamed ? ` — task renamed to ${taskTitle}` : ""),
},
{
...(versionId ? { versionId } : {}),
@@ -247,7 +320,8 @@ export async function finalizePreview(jobId: string, machineId: string, body: Fi
return {
export: { id: updated.id, status: updated.status },
version: versionId ? { id: versionId } : null,
version: versionId ? { id: versionId, replaced: versionReplaced } : null,
task: exportRow.taskId ? { id: exportRow.taskId, title: taskTitle, renamed: taskRenamed } : null,
alreadyApplied: false,
};
});
@@ -293,3 +367,90 @@ export async function retryPreview(exportId: string, actorId?: string) {
};
});
}
/** Statuses a preview can be regenerated from — every state where the EXRs are known good. */
const REGENERATABLE_STATUSES: ExportStatus[] = ["READY_FOR_QC", "QC_FAILED", "PREVIEW_FAILED"];
export interface RegeneratePreviewInput {
/** Per-export override; omitted → re-read from the shot's slate fields. */
vfxScope?: string | null;
submissionNote?: string | null;
actorId?: string;
note?: string;
}
/**
* T11b — rebuild the preview for an export that already delivered one, after a
* slate or burn-in mistake was spotted in QC.
*
* Re-runs the *whole* preview stage rather than patching anything: the manifest
* is rebuilt from scratch, so the shot code, episode/scene, frame count, slate
* date and burn-ins are all re-derived from current data exactly as they are on
* a first-time preview. The validated EXRs are reused and the version number is
* untouched — this re-delivers the same version, it does not make a new one.
*
* Slate text authored on the web app's Slate tab (description, VFX scope,
* submission note) is picked up here: `vfxScope` and `submissionNote` are
* frozen onto the Export at submission time, so regenerating refreshes that
* snapshot from the shot unless the caller passes an explicit override.
*/
export async function regeneratePreview(exportId: string, input: RegeneratePreviewInput = {}) {
const maxAttempts = await getConfigNumber("render.maxAttempts");
return db.$transaction(async (tx) => {
const exportRow = await tx.export.findUnique({ where: { id: exportId } });
if (!exportRow) throw new PipelineError(404, "Export not found");
if (!REGENERATABLE_STATUSES.includes(exportRow.status)) {
throw new PipelineError(
409,
`Export is ${exportRow.status} — a preview can only be regenerated from ${REGENERATABLE_STATUSES.join(", ")}`
);
}
const shot = await tx.shot.findUniqueOrThrow({
where: { id: exportRow.shotId },
select: { slateVfxScope: true, slateSubmissionNote: true },
});
// Same precedence as createExport: explicit override → shot's slate field.
const vfxScope = input.vfxScope !== undefined ? input.vfxScope : (shot.slateVfxScope ?? null);
const submissionNote =
input.submissionNote !== undefined ? input.submissionNote : (shot.slateSubmissionNote ?? null);
const refreshed = { ...exportRow, vfxScope, submissionNote };
const manifest = await buildPreviewManifest(refreshed);
const last = await tx.renderJob.findFirst({
where: { exportId, type: "PREVIEW_ONLY" },
orderBy: { attempt: "desc" },
});
const job = await tx.renderJob.create({
data: {
type: "PREVIEW_ONLY",
exportId,
attempt: (last?.attempt ?? 0) + 1,
maxAttempts,
priority: last?.priority ?? 50,
manifest: manifest as unknown as Prisma.InputJsonValue,
},
});
const updated = await applyTransition(
tx,
exportRow,
"GENERATING_PREVIEW",
{
type: "USER",
id: input.actorId,
note: input.note ?? `Regenerate preview (attempt ${job.attempt})`,
},
{ vfxScope, submissionNote }
);
return {
export: { id: updated.id, status: updated.status },
renderJob: { id: job.id, attempt: job.attempt },
slate: { vfxScope, submissionNote, description: manifest.slate.description },
};
});
}
+5 -2
View File
@@ -24,8 +24,11 @@ export const EXPORT_TRANSITIONS: Record<ExportStatus, ExportStatus[]> = {
VALIDATION_FAILED: ["QUEUED", "SUPERSEDED"],
GENERATING_PREVIEW: ["PREVIEW_FAILED", "READY_FOR_QC"],
PREVIEW_FAILED: ["GENERATING_PREVIEW", "SUPERSEDED"],
READY_FOR_QC: ["QC_FAILED", "READY_FOR_DELIVERY", "SUPERSEDED"],
QC_FAILED: ["SUPERSEDED"],
// GENERATING_PREVIEW: a slate/burn-in mistake is caught *after* a successful
// preview, so the preview stage must be re-runnable without re-rendering the
// validated EXRs or burning a version number (T11b).
READY_FOR_QC: ["GENERATING_PREVIEW", "QC_FAILED", "READY_FOR_DELIVERY", "SUPERSEDED"],
QC_FAILED: ["GENERATING_PREVIEW", "SUPERSEDED"],
READY_FOR_DELIVERY: ["PACKAGED", "SUPERSEDED"],
PACKAGED: ["DELIVERED"],
DELIVERED: ["ARCHIVED"],