fix(delivery): separate packages by show, and number same-day deliveries
Deploy / deploy (push) Successful in 6m27s
Deploy / deploy (push) Successful in 6m27s
Two faults in how a package's folder is named, both of which put unrelated
files in one directory on the delivery volume.
The default layout had no {showId}, so every show's episode 101 resolved to
{deliveryRoot}/101/{packageName}. The token existed and was populated — it
just never appeared in the path. With hardlinked packages that means two
shows delivering the same episode number on the same day write into the same
folder, and identically named shots overwrite each other. reviewDir had the
same hole, and is worse there: reviewNameFor scopes its lookup by projectId,
so a second show computes the bare base name and lands on the first show's
folder instead of suffixing past it.
createDeliveryPackage also never checked for an existing package of the same
name. packageNameTemplate is date-only and packageNumber is a per-project
counter that is not in the template, so a second delivery on the same day got
an identical name and rootPath and built on top of the first. MOV reviews
already did this correctly, so nextReviewName moves to deliveries.ts as
nextPackageName and both paths share it; the review-side name is kept as an
alias because it reads better at that call site.
Putting {showId} ahead of {episode} exposes an empty segment on non-episodic
shows, so paths go through tidyPath, which collapses it and leaves the UNC
root alone.
Historic packages are unaffected: buildDeliveryJobManifest reads rootPath and
configSnapshot off the record, so only new packages use the new layout. A
project with its own deliveryConfig.layout in the database still overrides
these defaults.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,10 +46,12 @@ export const DELIVERY_CONFIG_DEFAULT: DeliveryConfig = {
|
||||
packageNameTemplate: "{yymmdd}_Delivery",
|
||||
reviewNameTemplate: "{yyyymmdd}_Producer_review",
|
||||
layout: {
|
||||
packageDir: "{deliveryRoot}/{episode}/{packageName}",
|
||||
// {showId} is not optional in practice: without it every show's episode 101
|
||||
// lands in one folder on the delivery volume.
|
||||
packageDir: "{deliveryRoot}/{showId}/{episode}/{packageName}",
|
||||
shotDir: "{packageDir}/{shotCode}",
|
||||
reportFile: "{packageDir}/{packageName}_report.csv",
|
||||
reviewDir: "{deliveryRoot}/PRODUCER_REVIEWS/{packageName}",
|
||||
reviewDir: "{deliveryRoot}/{showId}/PRODUCER_REVIEWS/{packageName}",
|
||||
},
|
||||
deliveryRoot: "//SAN/DELIVERY",
|
||||
includeMovs: true,
|
||||
@@ -108,6 +110,36 @@ export function applyTokens(template: string, tokens: Partial<TokenValues>): str
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapse the empty segment an unset token leaves behind — a non-episodic
|
||||
* show resolves {episode} to "" and would otherwise build ".../SHOW//NAME".
|
||||
* The leading pair of a UNC root (//SAN/...) is preserved.
|
||||
*/
|
||||
export function tidyPath(path: string): string {
|
||||
const uncPrefix = /^\/\//.test(path) ? "//" : "";
|
||||
return uncPrefix + path.slice(uncPrefix.length).replace(/\/{2,}/g, "/").replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* Second and later packages sharing a base name get `_02`, `_03`, ... Numbering
|
||||
* counts every package built under that base — cancelled and failed ones
|
||||
* included — so a number is never reused for a different folder.
|
||||
*/
|
||||
export function nextPackageName(base: string, existingNames: string[]): string {
|
||||
const pattern = new RegExp(`^${escapeRegExp(base)}(?:_(\\d+))?$`);
|
||||
let highest = 0;
|
||||
for (const name of existingNames) {
|
||||
const match = pattern.exec(name);
|
||||
if (!match) continue;
|
||||
highest = Math.max(highest, match[1] ? Number.parseInt(match[1], 10) : 1);
|
||||
}
|
||||
return highest === 0 ? base : `${base}_${String(highest + 1).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
export function dateTokens(date: Date) {
|
||||
const yyyy = String(date.getFullYear());
|
||||
const mm = String(date.getMonth() + 1).padStart(2, "0");
|
||||
@@ -280,8 +312,17 @@ export async function createDeliveryPackage(input: CreateDeliveryInput, userId:
|
||||
versionString: "",
|
||||
packageNumber: String(packageNumber),
|
||||
};
|
||||
tokens.packageName = input.options?.name ?? applyTokens(config.packageNameTemplate, tokens);
|
||||
tokens.packageDir = applyTokens(config.layout.packageDir, tokens);
|
||||
// A second delivery on the same day is normal — a retake batch, or a client
|
||||
// asking for the rest of a sequence — and the date-only template gives it a
|
||||
// name identical to the morning's. Suffix it the way MOV reviews already
|
||||
// are, so it gets its own folder instead of merging into the first one.
|
||||
const baseName = applyTokens(config.packageNameTemplate, tokens);
|
||||
const sameBase = await tx.deliveryPackage.findMany({
|
||||
where: { projectId: project.id, kind: "EXR_DELIVERY", name: { startsWith: baseName } },
|
||||
select: { name: true },
|
||||
});
|
||||
tokens.packageName = input.options?.name ?? nextPackageName(baseName, sameBase.map((p) => p.name));
|
||||
tokens.packageDir = tidyPath(applyTokens(config.layout.packageDir, tokens));
|
||||
|
||||
const pkg = await tx.deliveryPackage.create({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user