Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fe420b9455 | |||
| 2a8888089f | |||
| a073f92da3 | |||
| 04e5eb123a | |||
| 75f9258b69 | |||
| 269a5cbfda |
@@ -70,6 +70,59 @@ public class PrepareOutputDirTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The version folder holds the preview MOV/MP4 built from the same
|
||||
/// basename. A shot re-rendered at the same version — the "No preview"
|
||||
/// workflow, where the EXRs are re-exported unscaled and the earlier MOV is
|
||||
/// inherited as the review media — must not have that MOV cleared out from
|
||||
/// under it before aerender starts.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void KeepsPreviewMediaSharingThePatternPrefix()
|
||||
{
|
||||
var dir = Path.Combine(Path.GetTempPath(), "vfxr-test-" + Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(dir);
|
||||
try
|
||||
{
|
||||
File.WriteAllText(Path.Combine(dir, "SHOT_cmp_TT_v004.1001.exr"), "old");
|
||||
File.WriteAllText(Path.Combine(dir, "SHOT_cmp_TT_v004.mov"), "delivery mov");
|
||||
File.WriteAllText(Path.Combine(dir, "SHOT_cmp_TT_v004.mp4"), "review mp4");
|
||||
|
||||
AerenderRunner.PrepareOutputDir(dir, "SHOT_cmp_TT_v004.[####].exr");
|
||||
|
||||
Assert.False(File.Exists(Path.Combine(dir, "SHOT_cmp_TT_v004.1001.exr")));
|
||||
Assert.True(File.Exists(Path.Combine(dir, "SHOT_cmp_TT_v004.mov")));
|
||||
Assert.True(File.Exists(Path.Combine(dir, "SHOT_cmp_TT_v004.mp4")));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Directory.Delete(dir, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearsOnlyThisVersionsFrames()
|
||||
{
|
||||
var dir = Path.Combine(Path.GetTempPath(), "vfxr-test-" + Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(dir);
|
||||
try
|
||||
{
|
||||
File.WriteAllText(Path.Combine(dir, "SHOT_cmp_TT_v004.1001.exr"), "old");
|
||||
File.WriteAllText(Path.Combine(dir, "SHOT_cmp_TT_v005.1001.exr"), "other version");
|
||||
File.WriteAllText(Path.Combine(dir, "OTHERSHOT_cmp_TT_v004.1001.exr"), "other shot");
|
||||
|
||||
AerenderRunner.PrepareOutputDir(dir, "SHOT_cmp_TT_v004.[####].exr");
|
||||
|
||||
Assert.False(File.Exists(Path.Combine(dir, "SHOT_cmp_TT_v004.1001.exr")));
|
||||
Assert.True(File.Exists(Path.Combine(dir, "SHOT_cmp_TT_v005.1001.exr")));
|
||||
Assert.True(File.Exists(Path.Combine(dir, "OTHERSHOT_cmp_TT_v004.1001.exr")));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Directory.Delete(dir, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreatesMissingDirectory()
|
||||
{
|
||||
|
||||
@@ -234,26 +234,30 @@ public sealed class AerenderRunner
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// §7.3: outputDir is created before launch; a pre-existing non-empty dir
|
||||
/// can only hold output from a previous crashed attempt of this same
|
||||
/// immutable version. Safety guard: only files matching the job's own
|
||||
/// output pattern prefix are ever deleted.
|
||||
/// §7.3: outputDir is created before launch; a pre-existing dir can hold
|
||||
/// frames from a previous crashed attempt, which aerender would otherwise
|
||||
/// leave interleaved with this attempt's. Safety guard: only files matching
|
||||
/// the job's own output pattern — its prefix *and* its extension — are ever
|
||||
/// deleted.
|
||||
///
|
||||
/// The extension is not optional. The version folder is shared with the
|
||||
/// preview stage, whose MOV and MP4 are built from the same basename
|
||||
/// (preview.ts: `{outputDir}/{base}.mov`), so prefix alone also matches
|
||||
/// them. A version folder can legitimately be rendered into twice — the
|
||||
/// output path is keyed on the shot's manually-set version, not on the
|
||||
/// export — and on a no-preview re-render (Export.skipPreview) the media
|
||||
/// that gets inherited is precisely the MOV sitting in this folder.
|
||||
/// Deleting it left the export pointing at a file that no longer existed,
|
||||
/// and delivery silently packaged the EXRs without their viewing copy.
|
||||
/// </summary>
|
||||
/// <summary>Filename prefix of an output pattern ("X.[####].exr" → "X").</summary>
|
||||
internal static string OutputPatternPrefix(string outputPattern)
|
||||
{
|
||||
var bracket = outputPattern.IndexOf('[');
|
||||
return bracket > 0 ? outputPattern[..bracket].TrimEnd('.') : Path.GetFileNameWithoutExtension(outputPattern);
|
||||
}
|
||||
|
||||
internal static void PrepareOutputDir(string outputDirLocal, string outputPattern)
|
||||
{
|
||||
Directory.CreateDirectory(outputDirLocal);
|
||||
var prefix = OutputPatternPrefix(outputPattern);
|
||||
if (string.IsNullOrEmpty(prefix)) return;
|
||||
var pattern = SequencePattern.FromOutputPattern(outputPattern);
|
||||
if (string.IsNullOrEmpty(pattern.Prefix)) return;
|
||||
foreach (var file in Directory.EnumerateFiles(outputDirLocal))
|
||||
{
|
||||
if (Path.GetFileName(file).StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
|
||||
if (pattern.MatchesOutputFile(Path.GetFileName(file)))
|
||||
{
|
||||
try { File.Delete(file); } catch { /* locked leftovers surface as an aerender error */ }
|
||||
}
|
||||
|
||||
@@ -76,12 +76,15 @@ public sealed class JobExecutor
|
||||
{
|
||||
long totalBytes = 0;
|
||||
int fileCount = 0;
|
||||
var prefix = AerenderRunner.OutputPatternPrefix(manifest.OutputPattern);
|
||||
// Prefix and extension both: the preview MOV/MP4 for this
|
||||
// version share the basename and live in this same folder, and
|
||||
// counting them as frames would inflate the EXR stats.
|
||||
var pattern = SequencePattern.FromOutputPattern(manifest.OutputPattern);
|
||||
try
|
||||
{
|
||||
foreach (var f in Directory.EnumerateFiles(outputDirLocal))
|
||||
{
|
||||
if (!Path.GetFileName(f).StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) continue;
|
||||
if (!pattern.MatchesOutputFile(Path.GetFileName(f))) continue;
|
||||
fileCount++;
|
||||
totalBytes += new FileInfo(f).Length;
|
||||
}
|
||||
@@ -94,8 +97,8 @@ public sealed class JobExecutor
|
||||
// range, template mismatch, silently swallowed error).
|
||||
// Until Phase 3 validation exists, an empty output dir must
|
||||
// never become READY_FOR_QC.
|
||||
_log.LogError("Job {JobId}: aerender exited 0 but no \"{Prefix}*\" files exist in {Dir} — reporting failure",
|
||||
job.Id, prefix, outputDirLocal);
|
||||
_log.LogError("Job {JobId}: aerender exited 0 but no \"{Prefix}*{Ext}\" files exist in {Dir} — reporting failure",
|
||||
job.Id, pattern.Prefix, pattern.Extension, outputDirLocal);
|
||||
_spooler.Enqueue("fail", job.Id, new Dictionary<string, object?>
|
||||
{
|
||||
["machineId"] = machineId,
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
every change that gets published. publish.ps1 appends the git SHA via
|
||||
SourceRevisionId, giving "1.1.0+feb1c7b".
|
||||
-->
|
||||
<Version>1.6.0</Version>
|
||||
<Version>1.6.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -645,6 +645,16 @@ public sealed class SequencePattern
|
||||
return new SequencePattern { Prefix = prefix, Extension = ext, Padding = padding };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether a filename belongs to *this* render's output: the pattern's own
|
||||
/// prefix and extension. A version folder also holds the preview MOV and
|
||||
/// MP4, which are built from the same basename and so share the prefix —
|
||||
/// only the extension separates them from the frames.
|
||||
/// </summary>
|
||||
public bool MatchesOutputFile(string fileName) =>
|
||||
fileName.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase)
|
||||
&& fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public int? FrameNumberOf(string fileName) => FrameFromName(fileName);
|
||||
|
||||
/// <summary>`UNG_102_019_010_cmp_TT_v005.01001.exr` → 1001.</summary>
|
||||
|
||||
@@ -652,6 +652,57 @@ export async function bulkUpdateDueDates(
|
||||
return { success: true, updated: shots.length };
|
||||
}
|
||||
|
||||
// ── Bulk Assign Artist ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Point a selection of shots at one artist, or clear the assignment when
|
||||
* `artistId` is null. Mirrors the single-shot artist field in updateShot —
|
||||
* the assignment is a plain column write with no notification, so reassigning
|
||||
* a batch during planning stays quiet.
|
||||
*/
|
||||
export async function bulkAssignArtist(shotIds: string[], artistId: string | null) {
|
||||
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 ids = z.array(z.string().cuid()).parse(shotIds);
|
||||
if (!ids.length) return { success: true, updated: 0, artistName: null as string | null };
|
||||
|
||||
let artistName: string | null = null;
|
||||
if (artistId) {
|
||||
const artist = await db.user.findUnique({
|
||||
where: { id: z.string().cuid().parse(artistId) },
|
||||
select: { id: true, name: true, email: true, role: true, isActive: true },
|
||||
});
|
||||
// A deactivated user or a client account must never end up owning a shot,
|
||||
// so this is checked here rather than trusting whatever the picker sent.
|
||||
if (!artist || !artist.isActive || artist.role === "CLIENT") {
|
||||
throw new Error("That user cannot be assigned shots");
|
||||
}
|
||||
artistName = artist.name ?? artist.email;
|
||||
}
|
||||
|
||||
const shots = await db.shot.findMany({
|
||||
where: { id: { in: ids } },
|
||||
select: { id: true, projectId: true },
|
||||
});
|
||||
if (shots.length !== ids.length) throw new Error("Some shots not found");
|
||||
|
||||
await db.shot.updateMany({
|
||||
where: { id: { in: ids } },
|
||||
data: { artistId },
|
||||
});
|
||||
|
||||
for (const pid of [...new Set(shots.map((s) => s.projectId))]) {
|
||||
revalidatePath(`/projects/${pid}`);
|
||||
}
|
||||
revalidatePath(`/shot-status`);
|
||||
|
||||
return { success: true, updated: shots.length, artistName };
|
||||
}
|
||||
|
||||
// ── Bulk Delete Shots ─────────────────────────────────────────────────────────
|
||||
|
||||
export async function bulkDeleteShots(shotIds: string[]) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectSeparator,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
@@ -28,8 +29,9 @@ import {
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { updateShotNotes, bulkUpdateDueDates, bulkDeleteShots, toggleKeyShot, toggleScaledShot } from "@/actions/shots";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { cn, getInitials } from "@/lib/utils";
|
||||
import { updateShotNotes, bulkUpdateDueDates, bulkAssignArtist, bulkDeleteShots, toggleKeyShot, toggleScaledShot } from "@/actions/shots";
|
||||
import { previewMovReview, buildMovReview } from "@/actions/deliveries";
|
||||
import { useToast } from "@/components/ui/use-toast";
|
||||
import {
|
||||
@@ -50,6 +52,7 @@ import {
|
||||
ChevronsUpDown,
|
||||
Clapperboard,
|
||||
Scaling,
|
||||
UserPlus,
|
||||
} from "lucide-react";
|
||||
import { format } from "date-fns";
|
||||
import { shotThumbnail } from "@/lib/shot-thumbnail";
|
||||
@@ -74,6 +77,13 @@ type ShotRow = {
|
||||
shotGroup: { id: string; name: string } | null;
|
||||
};
|
||||
|
||||
interface Artist {
|
||||
id: string;
|
||||
name: string | null;
|
||||
email: string;
|
||||
image: string | null;
|
||||
}
|
||||
|
||||
interface Project {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -87,6 +97,7 @@ interface ShotStatusClientProps {
|
||||
selectedProject: Project | null;
|
||||
shots: ShotRow[];
|
||||
episodeDueDates: { episode: string; dueDate: Date | string }[];
|
||||
artists: Artist[];
|
||||
canManage: boolean;
|
||||
}
|
||||
|
||||
@@ -225,6 +236,103 @@ function BulkDueDateDialog({
|
||||
);
|
||||
}
|
||||
|
||||
// ── BulkAssignArtistDialog ────────────────────────────────────────────────────
|
||||
|
||||
const UNASSIGN = "__unassign__";
|
||||
|
||||
/**
|
||||
* Hand a selection of shots to one artist, or clear the assignment.
|
||||
*
|
||||
* Unassigning is offered as an explicit choice rather than a separate menu
|
||||
* entry — reassignment and hand-back are the same production move, and the
|
||||
* confirm button changes wording so nobody clears a batch by accident.
|
||||
*/
|
||||
function BulkAssignArtistDialog({
|
||||
open,
|
||||
onClose,
|
||||
onApply,
|
||||
artists,
|
||||
count,
|
||||
}: {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
onApply: (artistId: string | null) => Promise<void>;
|
||||
artists: Artist[];
|
||||
count: number;
|
||||
}) {
|
||||
const [value, setValue] = useState("");
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
useEffect(() => {
|
||||
if (open) setValue("");
|
||||
}, [open]);
|
||||
|
||||
const handleApply = () => {
|
||||
if (!value) return;
|
||||
startTransition(async () => {
|
||||
await onApply(value === UNASSIGN ? null : value);
|
||||
});
|
||||
};
|
||||
|
||||
const unassigning = value === UNASSIGN;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(o) => { if (!o && !isPending) onClose(); }}>
|
||||
<DialogContent className="sm:max-w-sm">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Assign Artist</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<p className="text-sm text-zinc-400 -mt-1">
|
||||
Applying to <span className="text-white font-medium">{count}</span>{" "}
|
||||
shot{count !== 1 ? "s" : ""}
|
||||
</p>
|
||||
|
||||
<div className="space-y-1.5 pt-1">
|
||||
<label className="text-xs font-medium text-zinc-400">Artist</label>
|
||||
<Select value={value} onValueChange={setValue}>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Select an artist..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{artists.map((a) => (
|
||||
<SelectItem key={a.id} value={a.id}>
|
||||
<span className="flex items-center gap-2">
|
||||
<Avatar className="h-5 w-5">
|
||||
<AvatarImage src={a.image ?? undefined} />
|
||||
<AvatarFallback className="text-[9px] bg-zinc-700 text-zinc-300">
|
||||
{getInitials(a.name ?? a.email)}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
{a.name ?? a.email}
|
||||
</span>
|
||||
</SelectItem>
|
||||
))}
|
||||
<SelectSeparator />
|
||||
<SelectItem value={UNASSIGN}>
|
||||
<span className="text-zinc-400">Unassign</span>
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p className="text-xs text-zinc-500 pt-1">
|
||||
This replaces whoever is currently on {count === 1 ? "the shot" : "these shots"}.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="mt-2">
|
||||
<Button variant="ghost" onClick={onClose} disabled={isPending}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleApply} disabled={!value || isPending}>
|
||||
{isPending && <Loader2 className="h-3.5 w-3.5 mr-1.5 animate-spin" />}
|
||||
{unassigning ? "Unassign" : "Assign"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function BulkDeleteDialog({
|
||||
open,
|
||||
onClose,
|
||||
@@ -601,6 +709,7 @@ function ShotTable({
|
||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-32">Thumb</th>
|
||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500">Shot</th>
|
||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-32">Status</th>
|
||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-40">Artist</th>
|
||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500 w-32">Due Date</th>
|
||||
<th className="text-left py-2 px-3 text-xs font-medium text-zinc-500">Notes</th>
|
||||
<th className="py-2 px-3 text-xs font-medium text-zinc-500 w-20 text-center">
|
||||
@@ -700,6 +809,25 @@ function ShotTable({
|
||||
</Badge>
|
||||
</td>
|
||||
|
||||
{/* Artist */}
|
||||
<td className="py-2 px-3">
|
||||
{shot.artist ? (
|
||||
<span className="flex items-center gap-2 min-w-0">
|
||||
<Avatar className="h-5 w-5 shrink-0">
|
||||
<AvatarImage src={shot.artist.image ?? undefined} />
|
||||
<AvatarFallback className="text-[9px] bg-zinc-700 text-zinc-300">
|
||||
{getInitials(shot.artist.name ?? shot.artist.email)}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<span className="text-xs text-zinc-300 truncate">
|
||||
{shot.artist.name ?? shot.artist.email}
|
||||
</span>
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-xs text-zinc-600 italic">Unassigned</span>
|
||||
)}
|
||||
</td>
|
||||
|
||||
{/* Due date */}
|
||||
<td className="py-2 px-3">
|
||||
{dueDate ? (
|
||||
@@ -745,6 +873,7 @@ export function ShotStatusClient({
|
||||
selectedProject,
|
||||
shots,
|
||||
episodeDueDates,
|
||||
artists,
|
||||
canManage,
|
||||
}: ShotStatusClientProps) {
|
||||
const router = useRouter();
|
||||
@@ -793,6 +922,7 @@ export function ShotStatusClient({
|
||||
}
|
||||
}, [selectedProjectId]);
|
||||
const [dueDateDialogOpen, setDueDateDialogOpen] = useState(false);
|
||||
const [assignDialogOpen, setAssignDialogOpen] = useState(false);
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
const [movReviewDialogOpen, setMovReviewDialogOpen] = useState(false);
|
||||
|
||||
@@ -868,6 +998,26 @@ export function ShotStatusClient({
|
||||
}
|
||||
};
|
||||
|
||||
const handleBulkAssignArtist = async (artistId: string | null) => {
|
||||
try {
|
||||
const result = await bulkAssignArtist([...selectedIds], artistId);
|
||||
toast({
|
||||
title: result.artistName
|
||||
? `${result.updated} shot${result.updated !== 1 ? "s" : ""} assigned to ${result.artistName}`
|
||||
: `${result.updated} shot${result.updated !== 1 ? "s" : ""} unassigned`,
|
||||
});
|
||||
setAssignDialogOpen(false);
|
||||
clearSelection();
|
||||
router.refresh();
|
||||
} catch (e) {
|
||||
toast({
|
||||
title: "Failed to assign artist",
|
||||
description: e instanceof Error ? e.message : undefined,
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleBulkDelete = async () => {
|
||||
try {
|
||||
const result = await bulkDeleteShots([...selectedIds]);
|
||||
@@ -1040,6 +1190,10 @@ export function ShotStatusClient({
|
||||
<CalendarDays className="h-3.5 w-3.5 mr-2" />
|
||||
Change Due Date
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setAssignDialogOpen(true)}>
|
||||
<UserPlus className="h-3.5 w-3.5 mr-2" />
|
||||
Assign Artist
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setMovReviewDialogOpen(true)}>
|
||||
<Clapperboard className="h-3.5 w-3.5 mr-2" />
|
||||
Build MOV Review Package
|
||||
@@ -1249,6 +1403,15 @@ export function ShotStatusClient({
|
||||
count={selectionCount}
|
||||
/>
|
||||
|
||||
{/* Bulk artist assignment dialog */}
|
||||
<BulkAssignArtistDialog
|
||||
open={assignDialogOpen}
|
||||
onClose={() => setAssignDialogOpen(false)}
|
||||
onApply={handleBulkAssignArtist}
|
||||
artists={artists}
|
||||
count={selectionCount}
|
||||
/>
|
||||
|
||||
{/* Bulk delete dialog */}
|
||||
<BulkDeleteDialog
|
||||
open={deleteDialogOpen}
|
||||
|
||||
@@ -19,6 +19,15 @@ async function getEpisodeDueDatesForProject(projectId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Everyone a shot can be handed to — clients and deactivated accounts excluded. */
|
||||
async function getAssignableArtists() {
|
||||
return db.user.findMany({
|
||||
where: { isActive: true, role: { not: "CLIENT" } },
|
||||
select: { id: true, name: true, email: true, image: true },
|
||||
orderBy: { name: "asc" },
|
||||
});
|
||||
}
|
||||
|
||||
async function getShotsForProject(projectId: string) {
|
||||
return db.shot.findMany({
|
||||
where: { projectId },
|
||||
@@ -62,10 +71,11 @@ export default async function ShotStatusPage({
|
||||
const { projectId } = await searchParams;
|
||||
const canManage = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role);
|
||||
|
||||
const [projects, shots, episodeDueDates] = await Promise.all([
|
||||
const [projects, shots, episodeDueDates, artists] = await Promise.all([
|
||||
getProjects(),
|
||||
projectId ? getShotsForProject(projectId) : Promise.resolve([]),
|
||||
projectId ? getEpisodeDueDatesForProject(projectId) : Promise.resolve([]),
|
||||
canManage ? getAssignableArtists() : Promise.resolve([]),
|
||||
]);
|
||||
|
||||
const selectedProject = projects.find((p) => p.id === projectId) ?? null;
|
||||
@@ -77,6 +87,7 @@ export default async function ShotStatusPage({
|
||||
selectedProject={selectedProject}
|
||||
shots={shots as any}
|
||||
episodeDueDates={episodeDueDates}
|
||||
artists={artists}
|
||||
canManage={canManage}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState, type RefObject } from "react";
|
||||
import {
|
||||
blankingInsets,
|
||||
findAspectPreset,
|
||||
isFullFrame,
|
||||
letterboxRect,
|
||||
type BlankingMode,
|
||||
} from "@/lib/aspect-overlays";
|
||||
|
||||
interface AspectOverlayProps {
|
||||
/** Preset id, or "off" — anything unknown draws nothing. */
|
||||
presetId: string;
|
||||
mode: BlankingMode;
|
||||
videoRef: RefObject<HTMLVideoElement | null>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivery blanking drawn over the video. Purely visual: it never touches the
|
||||
* video element, sits under the annotation canvas, and passes every pointer
|
||||
* event through so click-to-play still works underneath it.
|
||||
*/
|
||||
export function AspectOverlay({ presetId, mode, videoRef }: AspectOverlayProps) {
|
||||
const preset = findAspectPreset(presetId);
|
||||
const [box, setBox] = useState<{
|
||||
top: number;
|
||||
bottom: number;
|
||||
left: number;
|
||||
right: number;
|
||||
rect: { left: number; top: number; width: number; height: number };
|
||||
} | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const video = videoRef.current;
|
||||
if (!video || !preset) {
|
||||
setBox(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const measure = () => {
|
||||
const rect = letterboxRect(
|
||||
video.clientWidth,
|
||||
video.clientHeight,
|
||||
video.videoWidth,
|
||||
video.videoHeight
|
||||
);
|
||||
// Before metadata lands videoWidth is 0 and there is nothing to measure.
|
||||
if (!rect) {
|
||||
setBox(null);
|
||||
return;
|
||||
}
|
||||
const insets = blankingInsets(rect, preset.ratio);
|
||||
setBox(isFullFrame(insets) ? null : { ...insets, rect });
|
||||
};
|
||||
|
||||
measure();
|
||||
|
||||
// The picture rect moves on layout changes (panel resize, fullscreen) and
|
||||
// on metadata, which is when intrinsic dimensions first exist.
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(video);
|
||||
video.addEventListener("loadedmetadata", measure);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
video.removeEventListener("loadedmetadata", measure);
|
||||
};
|
||||
}, [preset, videoRef]);
|
||||
|
||||
if (!preset || !box) return null;
|
||||
|
||||
const { rect } = box;
|
||||
const barClass =
|
||||
mode === "solid"
|
||||
? "absolute bg-black"
|
||||
: "absolute bg-black/60 ring-1 ring-inset ring-white/25";
|
||||
|
||||
// Each bar is positioned against the picture rect, not the element box, so
|
||||
// blanking lands on the image itself whatever shape the player is.
|
||||
const horizontal = box.top > 0;
|
||||
|
||||
return (
|
||||
// No z-index: the annotation canvas is also absolutely positioned and comes
|
||||
// later in the DOM, so it stays on top and marks drawn over a blanked area
|
||||
// remain visible.
|
||||
<div
|
||||
className="pointer-events-none absolute inset-0"
|
||||
aria-hidden="true"
|
||||
data-testid="aspect-overlay"
|
||||
>
|
||||
{horizontal ? (
|
||||
<>
|
||||
<div
|
||||
className={barClass}
|
||||
style={{ left: rect.left, top: rect.top, width: rect.width, height: box.top }}
|
||||
/>
|
||||
<div
|
||||
className={barClass}
|
||||
style={{
|
||||
left: rect.left,
|
||||
top: rect.top + rect.height - box.bottom,
|
||||
width: rect.width,
|
||||
height: box.bottom,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div
|
||||
className={barClass}
|
||||
style={{ left: rect.left, top: rect.top, width: box.left, height: rect.height }}
|
||||
/>
|
||||
<div
|
||||
className={barClass}
|
||||
style={{
|
||||
left: rect.left + rect.width - box.right,
|
||||
top: rect.top,
|
||||
width: box.right,
|
||||
height: rect.height,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="absolute bottom-3 right-3 rounded bg-black/70 px-2 py-1 font-mono text-[11px] text-zinc-300">
|
||||
{preset.label}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
Pencil,
|
||||
Eye,
|
||||
EyeOff,
|
||||
RectangleHorizontal,
|
||||
} from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -20,9 +21,17 @@ import {
|
||||
TooltipContent,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectSeparator,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { useReviewStore } from "@/hooks/use-review-player";
|
||||
import { frameToTimecode } from "@/lib/frame-utils";
|
||||
import { ASPECT_OFF, ASPECT_PRESETS } from "@/lib/aspect-overlays";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const PLAYBACK_RATES = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2];
|
||||
@@ -58,9 +67,13 @@ export function PlaybackControls({
|
||||
playbackRate,
|
||||
isAnnotating,
|
||||
showAnnotations,
|
||||
aspectPresetId,
|
||||
blankingMode,
|
||||
setPlaybackRate,
|
||||
setAnnotating,
|
||||
setShowAnnotations,
|
||||
setAspectPresetId,
|
||||
setBlankingMode,
|
||||
} = useReviewStore();
|
||||
|
||||
const handleRateChange = (val: string) => {
|
||||
@@ -69,6 +82,8 @@ export function PlaybackControls({
|
||||
setPlaybackRate(rate);
|
||||
};
|
||||
|
||||
const blankingOn = aspectPresetId !== ASPECT_OFF;
|
||||
|
||||
const timecode = frameToTimecode(currentFrame, fps);
|
||||
|
||||
return (
|
||||
@@ -216,6 +231,57 @@ export function PlaybackControls({
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* Delivery blanking — hidden on mobile */}
|
||||
<div className="hidden sm:contents">
|
||||
<Select value={aspectPresetId} onValueChange={setAspectPresetId}>
|
||||
<SelectTrigger
|
||||
className={cn(
|
||||
"h-7 w-24 text-xs border-0 bg-white/5 px-2",
|
||||
blankingOn ? "text-amber-400" : "text-zinc-300"
|
||||
)}
|
||||
>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={ASPECT_OFF} className="text-xs">
|
||||
No blanking
|
||||
</SelectItem>
|
||||
<SelectSeparator />
|
||||
{ASPECT_PRESETS.map((p) => (
|
||||
<SelectItem key={p.id} value={p.id} className="text-xs">
|
||||
<span className="font-mono">{p.label}</span>
|
||||
<span className="ml-2 text-zinc-500">{p.note}</span>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
{blankingOn && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className={cn(
|
||||
"text-zinc-400 hover:text-white",
|
||||
blankingMode === "guide" && "text-amber-400 bg-amber-400/10"
|
||||
)}
|
||||
onClick={() =>
|
||||
setBlankingMode(blankingMode === "solid" ? "guide" : "solid")
|
||||
}
|
||||
>
|
||||
<RectangleHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
{blankingMode === "solid"
|
||||
? "Dim the crop instead of hiding it"
|
||||
: "Hide the crop behind solid bars"}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Annotation toggle */}
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
import { useReviewStore } from "@/hooks/use-review-player";
|
||||
import { AnnotationCanvas } from "@/components/annotations/AnnotationCanvas";
|
||||
import { AnnotationTools } from "@/components/annotations/AnnotationTools";
|
||||
import { AspectOverlay } from "./AspectOverlay";
|
||||
import { FrameTimeline } from "./FrameTimeline";
|
||||
import { PlaybackControls } from "./PlaybackControls";
|
||||
import { timeToFrame, frameToTime, durationToFrameCount } from "@/lib/frame-utils";
|
||||
@@ -68,6 +69,8 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
||||
currentFrame,
|
||||
isAnnotating,
|
||||
showAnnotations,
|
||||
aspectPresetId,
|
||||
blankingMode,
|
||||
setPlaying,
|
||||
setCurrentFrame,
|
||||
setCurrentTime,
|
||||
@@ -283,6 +286,14 @@ export const ReviewPlayer = forwardRef<ReviewPlayerRef, ReviewPlayerProps>(
|
||||
playsInline
|
||||
/>
|
||||
|
||||
{/* Delivery blanking — under the annotation canvas, so a reviewer
|
||||
can still draw over a blanked area if they need to */}
|
||||
<AspectOverlay
|
||||
presetId={aspectPresetId}
|
||||
mode={blankingMode}
|
||||
videoRef={videoRef}
|
||||
/>
|
||||
|
||||
{/* Annotation canvas overlay */}
|
||||
<AnnotationCanvas
|
||||
versionId={versionId}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { create } from "zustand";
|
||||
import type { AnnotationTool } from "@/types";
|
||||
import { ASPECT_OFF, type BlankingMode } from "@/lib/aspect-overlays";
|
||||
|
||||
interface ReviewPlayerStore {
|
||||
// Playback
|
||||
@@ -19,6 +20,10 @@ interface ReviewPlayerStore {
|
||||
strokeWidth: number;
|
||||
showAnnotations: boolean;
|
||||
|
||||
// Delivery blanking — a viewing aid only, never part of the saved review
|
||||
aspectPresetId: string;
|
||||
blankingMode: BlankingMode;
|
||||
|
||||
// Config (set from version data)
|
||||
fps: number;
|
||||
totalFrames: number;
|
||||
@@ -37,6 +42,8 @@ interface ReviewPlayerStore {
|
||||
setSelectedColor: (color: string) => void;
|
||||
setStrokeWidth: (width: number) => void;
|
||||
setShowAnnotations: (show: boolean) => void;
|
||||
setAspectPresetId: (id: string) => void;
|
||||
setBlankingMode: (mode: BlankingMode) => void;
|
||||
setFps: (fps: number) => void;
|
||||
setTotalFrames: (frames: number) => void;
|
||||
reset: () => void;
|
||||
@@ -56,6 +63,8 @@ const initialState = {
|
||||
selectedColor: "#ef4444",
|
||||
strokeWidth: 2,
|
||||
showAnnotations: true,
|
||||
aspectPresetId: ASPECT_OFF,
|
||||
blankingMode: "solid" as BlankingMode,
|
||||
fps: 24,
|
||||
totalFrames: 0,
|
||||
};
|
||||
@@ -75,6 +84,8 @@ export const useReviewStore = create<ReviewPlayerStore>((set) => ({
|
||||
setSelectedColor: (selectedColor) => set({ selectedColor }),
|
||||
setStrokeWidth: (strokeWidth) => set({ strokeWidth }),
|
||||
setShowAnnotations: (showAnnotations) => set({ showAnnotations }),
|
||||
setAspectPresetId: (aspectPresetId) => set({ aspectPresetId }),
|
||||
setBlankingMode: (blankingMode) => set({ blankingMode }),
|
||||
setFps: (fps) => set({ fps }),
|
||||
setTotalFrames: (totalFrames) => set({ totalFrames }),
|
||||
reset: () => set(initialState),
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
ASPECT_PRESETS,
|
||||
blankingInsets,
|
||||
findAspectPreset,
|
||||
isFullFrame,
|
||||
letterboxRect,
|
||||
} from "./aspect-overlays";
|
||||
|
||||
describe("letterboxRect", () => {
|
||||
it("pillarboxes a 16:9 source in a squarer box", () => {
|
||||
const rect = letterboxRect(1000, 1000, 1920, 1080)!;
|
||||
expect(rect.width).toBeCloseTo(1000, 6);
|
||||
expect(rect.height).toBeCloseTo(562.5, 6);
|
||||
expect(rect.top).toBeCloseTo(218.75, 6);
|
||||
expect(rect.left).toBeCloseTo(0, 6);
|
||||
});
|
||||
|
||||
it("letterboxes a 16:9 source in a wider box", () => {
|
||||
const rect = letterboxRect(2000, 500, 1920, 1080)!;
|
||||
expect(rect.height).toBeCloseTo(500, 6);
|
||||
expect(rect.width).toBeCloseTo(888.888, 2);
|
||||
expect(rect.left).toBeCloseTo(555.555, 2);
|
||||
expect(rect.top).toBeCloseTo(0, 6);
|
||||
});
|
||||
|
||||
it("fills exactly when the box matches the source shape", () => {
|
||||
const rect = letterboxRect(1280, 720, 1920, 1080)!;
|
||||
expect(rect).toEqual({ left: 0, top: 0, width: 1280, height: 720 });
|
||||
});
|
||||
|
||||
it("returns null before metadata gives the video a size", () => {
|
||||
expect(letterboxRect(1000, 500, 0, 0)).toBeNull();
|
||||
expect(letterboxRect(0, 0, 1920, 1080)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("blankingInsets", () => {
|
||||
const hd = { left: 0, top: 0, width: 1920, height: 1080 };
|
||||
|
||||
it("blanks top and bottom for a wider delivery ratio", () => {
|
||||
const insets = blankingInsets(hd, 2.39);
|
||||
// 1920 / 2.39 = 803.35 tall, so 138.32 above and below.
|
||||
expect(insets.top).toBeCloseTo(138.3, 1);
|
||||
expect(insets.bottom).toBeCloseTo(138.3, 1);
|
||||
expect(insets.left).toBe(0);
|
||||
expect(insets.right).toBe(0);
|
||||
});
|
||||
|
||||
it("blanks left and right for a taller delivery ratio", () => {
|
||||
const insets = blankingInsets(hd, 4 / 3);
|
||||
// 1080 * 1.333 = 1440 wide, so 240 either side.
|
||||
expect(insets.left).toBeCloseTo(240, 4);
|
||||
expect(insets.right).toBeCloseTo(240, 4);
|
||||
expect(insets.top).toBe(0);
|
||||
expect(insets.bottom).toBe(0);
|
||||
});
|
||||
|
||||
it("draws nothing when the target matches the source", () => {
|
||||
expect(isFullFrame(blankingInsets(hd, 16 / 9))).toBe(true);
|
||||
});
|
||||
|
||||
it("suppresses a sub-pixel hairline rather than drawing one", () => {
|
||||
// 1.7777... vs a 1.778 label: a real ratio difference, but under half a pixel.
|
||||
expect(isFullFrame(blankingInsets(hd, 1.778))).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps the blanked area at the requested ratio", () => {
|
||||
const insets = blankingInsets(hd, 2.39);
|
||||
const visibleHeight = hd.height - insets.top - insets.bottom;
|
||||
expect(hd.width / visibleHeight).toBeCloseTo(2.39, 3);
|
||||
});
|
||||
|
||||
it("blanks a letterboxed picture rect, not the element box", () => {
|
||||
// 16:9 source shown in a tall panel: the picture is 1000x562.5 at y=218.75.
|
||||
const rect = letterboxRect(1000, 1000, 1920, 1080)!;
|
||||
const insets = blankingInsets(rect, 2.39);
|
||||
const visibleHeight = rect.height - insets.top - insets.bottom;
|
||||
expect(rect.width / visibleHeight).toBeCloseTo(2.39, 3);
|
||||
// Bars stay inside the picture, never spilling into the letterbox.
|
||||
expect(insets.top).toBeLessThan(rect.height / 2);
|
||||
});
|
||||
|
||||
it("is inert for a zero-size rect", () => {
|
||||
expect(isFullFrame(blankingInsets({ left: 0, top: 0, width: 0, height: 0 }, 2.39))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ASPECT_PRESETS", () => {
|
||||
it("has unique ids and positive ratios", () => {
|
||||
const ids = ASPECT_PRESETS.map((p) => p.id);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
for (const p of ASPECT_PRESETS) expect(p.ratio).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("runs widest to tallest", () => {
|
||||
const ratios = ASPECT_PRESETS.map((p) => p.ratio);
|
||||
expect([...ratios].sort((a, b) => b - a)).toEqual(ratios);
|
||||
});
|
||||
|
||||
it("looks up by id and ignores unknown ids", () => {
|
||||
expect(findAspectPreset("2.39")?.ratio).toBe(2.39);
|
||||
expect(findAspectPreset("off")).toBeNull();
|
||||
expect(findAspectPreset("nonsense")).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Aspect-ratio blanking for the review player.
|
||||
*
|
||||
* A shot is reviewed at the framing it was rendered at, but it is usually
|
||||
* *delivered* cropped — a 16:9 render shown 2.39:1, say. These helpers work out
|
||||
* where the delivered frame's edges fall so the player can lay bars over
|
||||
* everything outside them, without touching the video itself.
|
||||
*/
|
||||
|
||||
export type BlankingMode = "solid" | "guide";
|
||||
|
||||
export interface AspectPreset {
|
||||
id: string;
|
||||
/** What the reviewer picks from the list, e.g. "2.39:1". */
|
||||
label: string;
|
||||
/** Where it comes from, e.g. "Scope". Shown beside the label. */
|
||||
note: string;
|
||||
ratio: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivery ratios in wide-to-tall order, which is how a reviewer thinks about
|
||||
* them. Values are the real delivery numbers, not the rounded label: 2.39:1 is
|
||||
* 2.39, but 16:9 is 1.7778 rather than the 1.78 on the button.
|
||||
*/
|
||||
export const ASPECT_PRESETS: AspectPreset[] = [
|
||||
{ id: "2.39", label: "2.39:1", note: "Scope", ratio: 2.39 },
|
||||
{ id: "2.35", label: "2.35:1", note: "Classic scope", ratio: 2.35 },
|
||||
{ id: "2.20", label: "2.20:1", note: "70mm", ratio: 2.2 },
|
||||
{ id: "2.00", label: "2.00:1", note: "Univisium", ratio: 2 },
|
||||
{ id: "1.90", label: "1.90:1", note: "IMAX digital", ratio: 1.9 },
|
||||
{ id: "1.85", label: "1.85:1", note: "Flat", ratio: 1.85 },
|
||||
{ id: "1.78", label: "16:9", note: "1.78:1", ratio: 16 / 9 },
|
||||
{ id: "1.66", label: "1.66:1", note: "Super 16", ratio: 5 / 3 },
|
||||
{ id: "1.50", label: "3:2", note: "1.50:1", ratio: 1.5 },
|
||||
{ id: "1.33", label: "4:3", note: "1.33:1", ratio: 4 / 3 },
|
||||
{ id: "1.00", label: "1:1", note: "Square", ratio: 1 },
|
||||
{ id: "0.80", label: "4:5", note: "Social", ratio: 0.8 },
|
||||
{ id: "0.5625", label: "9:16", note: "Vertical", ratio: 9 / 16 },
|
||||
];
|
||||
|
||||
export const ASPECT_OFF = "off";
|
||||
|
||||
export function findAspectPreset(id: string): AspectPreset | null {
|
||||
return ASPECT_PRESETS.find((p) => p.id === id) ?? null;
|
||||
}
|
||||
|
||||
export interface Rect {
|
||||
left: number;
|
||||
top: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the picture actually sits inside an `object-contain` video element.
|
||||
* The element fills its box, but the image is letterboxed within it, so bars
|
||||
* drawn against the element's own edges would be wrong on any player whose
|
||||
* shape does not match the source.
|
||||
*/
|
||||
export function letterboxRect(
|
||||
containerWidth: number,
|
||||
containerHeight: number,
|
||||
videoWidth: number,
|
||||
videoHeight: number
|
||||
): Rect | null {
|
||||
if (
|
||||
!(containerWidth > 0) ||
|
||||
!(containerHeight > 0) ||
|
||||
!(videoWidth > 0) ||
|
||||
!(videoHeight > 0)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const scale = Math.min(containerWidth / videoWidth, containerHeight / videoHeight);
|
||||
const width = videoWidth * scale;
|
||||
const height = videoHeight * scale;
|
||||
|
||||
return {
|
||||
left: (containerWidth - width) / 2,
|
||||
top: (containerHeight - height) / 2,
|
||||
width,
|
||||
height,
|
||||
};
|
||||
}
|
||||
|
||||
export interface BlankingInsets {
|
||||
top: number;
|
||||
bottom: number;
|
||||
left: number;
|
||||
right: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* How thick the bars are on each edge, in pixels, for a target ratio inside a
|
||||
* given picture rect. A target wider than the source is blanked top and bottom;
|
||||
* a taller one is blanked left and right. Ratios within a pixel of the source
|
||||
* produce no bars at all rather than a hairline of rounding error.
|
||||
*/
|
||||
export function blankingInsets(rect: Rect, targetRatio: number): BlankingInsets {
|
||||
const none = { top: 0, bottom: 0, left: 0, right: 0 };
|
||||
if (!(targetRatio > 0) || !(rect.width > 0) || !(rect.height > 0)) return none;
|
||||
|
||||
const sourceRatio = rect.width / rect.height;
|
||||
|
||||
if (targetRatio > sourceRatio) {
|
||||
const bar = (rect.height - rect.width / targetRatio) / 2;
|
||||
return bar < 0.5 ? none : { top: bar, bottom: bar, left: 0, right: 0 };
|
||||
}
|
||||
|
||||
const bar = (rect.width - rect.height * targetRatio) / 2;
|
||||
return bar < 0.5 ? none : { top: 0, bottom: 0, left: bar, right: bar };
|
||||
}
|
||||
|
||||
/** True when the target crops nothing off this source — nothing to draw. */
|
||||
export function isFullFrame(insets: BlankingInsets): boolean {
|
||||
return !insets.top && !insets.bottom && !insets.left && !insets.right;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DELIVERY_CONFIG_DEFAULT, applyTokens, dateTokens, nextPackageName, tidyPath } from "./deliveries";
|
||||
|
||||
const BASE = "20260901_Delivery";
|
||||
|
||||
describe("nextPackageName", () => {
|
||||
it("uses the bare base for the first package of the day", () => {
|
||||
expect(nextPackageName(BASE, [])).toBe(BASE);
|
||||
});
|
||||
|
||||
it("suffixes later packages sharing the base", () => {
|
||||
expect(nextPackageName(BASE, [BASE])).toBe(`${BASE}_02`);
|
||||
expect(nextPackageName(BASE, [BASE, `${BASE}_02`])).toBe(`${BASE}_03`);
|
||||
});
|
||||
|
||||
it("never reuses a number after a gap", () => {
|
||||
expect(nextPackageName(BASE, [BASE, `${BASE}_02`, `${BASE}_04`])).toBe(`${BASE}_05`);
|
||||
});
|
||||
|
||||
it("ignores names that only share a prefix", () => {
|
||||
expect(nextPackageName(BASE, [`${BASE}_final`, "20260902_Delivery"])).toBe(BASE);
|
||||
});
|
||||
});
|
||||
|
||||
describe("delivery layout", () => {
|
||||
const tokens = {
|
||||
deliveryRoot: "//SAN/DELIVERY",
|
||||
showId: "ACME",
|
||||
episode: "101",
|
||||
packageName: BASE,
|
||||
};
|
||||
|
||||
it("separates shows so two shows' episode 101 cannot collide", () => {
|
||||
const acme = applyTokens(DELIVERY_CONFIG_DEFAULT.layout.packageDir, tokens);
|
||||
const other = applyTokens(DELIVERY_CONFIG_DEFAULT.layout.packageDir, { ...tokens, showId: "BRAVO" });
|
||||
expect(acme).toBe("//SAN/DELIVERY/ACME/101/20260901_Delivery");
|
||||
expect(other).not.toBe(acme);
|
||||
});
|
||||
|
||||
it("puts producer reviews under the show too", () => {
|
||||
expect(applyTokens(DELIVERY_CONFIG_DEFAULT.layout.reviewDir, tokens)).toBe(
|
||||
"//SAN/DELIVERY/ACME/PRODUCER_REVIEWS/20260901_Delivery"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("tidyPath", () => {
|
||||
it("drops the empty segment a non-episodic show leaves behind", () => {
|
||||
const raw = applyTokens(DELIVERY_CONFIG_DEFAULT.layout.packageDir, {
|
||||
deliveryRoot: "//SAN/DELIVERY",
|
||||
showId: "ACME",
|
||||
episode: "",
|
||||
packageName: BASE,
|
||||
});
|
||||
expect(tidyPath(raw)).toBe("//SAN/DELIVERY/ACME/20260901_Delivery");
|
||||
});
|
||||
|
||||
it("keeps the UNC root intact", () => {
|
||||
expect(tidyPath("//SAN/DELIVERY/ACME")).toBe("//SAN/DELIVERY/ACME");
|
||||
});
|
||||
|
||||
it("leaves a well-formed path alone", () => {
|
||||
expect(tidyPath("V:/DELIVERY/ACME/101/x")).toBe("V:/DELIVERY/ACME/101/x");
|
||||
});
|
||||
});
|
||||
|
||||
describe("per-episode numbering", () => {
|
||||
// The scoping itself lives in createDeliveryPackage's query, which passes
|
||||
// only the names already used by *this* episode. These pin the contract that
|
||||
// depends on: another episode's delivery must not push this one to _02.
|
||||
it("gives each episode's first delivery of the day the bare name", () => {
|
||||
const ep101 = nextPackageName(BASE, [BASE]);
|
||||
const ep102 = nextPackageName(BASE, []);
|
||||
expect(ep101).toBe(`${BASE}_02`);
|
||||
expect(ep102).toBe(BASE);
|
||||
});
|
||||
|
||||
it("keeps two episodes' same-named packages in separate folders", () => {
|
||||
const dirFor = (episode: string, packageName: string) =>
|
||||
tidyPath(
|
||||
applyTokens(DELIVERY_CONFIG_DEFAULT.layout.packageDir, {
|
||||
deliveryRoot: "//SAN/DELIVERY",
|
||||
showId: "ACME",
|
||||
episode,
|
||||
packageName,
|
||||
})
|
||||
);
|
||||
expect(dirFor("101", BASE)).toBe("//SAN/DELIVERY/ACME/101/20260901_Delivery");
|
||||
expect(dirFor("102", BASE)).toBe("//SAN/DELIVERY/ACME/102/20260901_Delivery");
|
||||
});
|
||||
});
|
||||
|
||||
describe("package name template", () => {
|
||||
it("names the day with a four-digit year", () => {
|
||||
const name = applyTokens(DELIVERY_CONFIG_DEFAULT.packageNameTemplate, dateTokens(new Date(2026, 8, 1)));
|
||||
expect(name).toBe("20260901_Delivery");
|
||||
});
|
||||
});
|
||||
@@ -43,13 +43,15 @@ export interface DeliveryConfig {
|
||||
}
|
||||
|
||||
export const DELIVERY_CONFIG_DEFAULT: DeliveryConfig = {
|
||||
packageNameTemplate: "{yymmdd}_Delivery",
|
||||
packageNameTemplate: "{yyyymmdd}_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,22 @@ 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.
|
||||
//
|
||||
// Numbering is per episode, not per project: packageDir already separates
|
||||
// episodes, so three episodes delivering today are each the day's first
|
||||
// delivery and each get the bare name. Only a repeat delivery of the *same*
|
||||
// episode collides, and only that one suffixes to _02.
|
||||
const baseName = applyTokens(config.packageNameTemplate, tokens);
|
||||
const sameBase = await tx.deliveryPackage.findMany({
|
||||
where: { projectId: project.id, episode, 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: {
|
||||
|
||||
@@ -6,7 +6,9 @@ import { getConfigNumber } from "./config";
|
||||
import {
|
||||
applyTokens,
|
||||
dateTokens,
|
||||
nextPackageName,
|
||||
resolveDeliveryConfig,
|
||||
tidyPath,
|
||||
type DeliveryConfig,
|
||||
type DeliveryManifest,
|
||||
type TokenValues,
|
||||
@@ -165,25 +167,12 @@ export async function resolveReviewCandidates(shotIds: string[]) {
|
||||
|
||||
// ── Folder naming ────────────────────────────────────────────────────────────
|
||||
|
||||
function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* `20260828_Producer_review`, then `_02`, `_03` for further reviews the same
|
||||
* day. Numbering counts every package built under that base — cancelled and
|
||||
* failed ones included — so a number is never reused for a different folder.
|
||||
* day. EXR deliveries now number the same way, so the rule lives in
|
||||
* deliveries.ts; this name is kept because it reads better at the call site.
|
||||
*/
|
||||
export function nextReviewName(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 const nextReviewName = nextPackageName;
|
||||
|
||||
async function reviewNameFor(
|
||||
tx: Prisma.TransactionClient | typeof db,
|
||||
@@ -243,7 +232,7 @@ export async function previewMovReviewPackage(shotIds: string[]) {
|
||||
const tokens = reviewTokens(config, project, commonEpisode(candidates), buildDate, 0);
|
||||
const base = applyTokens(config.reviewNameTemplate, tokens);
|
||||
tokens.packageName = await reviewNameFor(db, project.id, base);
|
||||
tokens.packageDir = applyTokens(config.layout.reviewDir, tokens);
|
||||
tokens.packageDir = tidyPath(applyTokens(config.layout.reviewDir, tokens));
|
||||
|
||||
return {
|
||||
projectId: project.id,
|
||||
@@ -299,7 +288,7 @@ export async function createMovReviewPackage(input: CreateMovReviewInput, userId
|
||||
const tokens = reviewTokens(config, project, episode, buildDate, packageNumber);
|
||||
const base = applyTokens(config.reviewNameTemplate, tokens);
|
||||
tokens.packageName = input.options?.name ?? (await reviewNameFor(tx, project.id, base));
|
||||
tokens.packageDir = applyTokens(config.layout.reviewDir, tokens);
|
||||
tokens.packageDir = tidyPath(applyTokens(config.layout.reviewDir, tokens));
|
||||
|
||||
const pkg = await tx.deliveryPackage.create({
|
||||
data: {
|
||||
|
||||
@@ -1112,7 +1112,7 @@ model DeliveryPackage {
|
||||
projectId String
|
||||
project Project @relation(fields: [projectId], references: [id])
|
||||
episode String // "101" — empty string on standard (non-episodic) shows, and on reviews spanning several
|
||||
name String // "260805_Delivery" | "20260828_Producer_review_02"
|
||||
name String // "20260805_Delivery" | "20260828_Producer_review_02"
|
||||
kind DeliveryKind @default(EXR_DELIVERY)
|
||||
packageNumber Int // sequential per project → "Package #15"
|
||||
status DeliveryStatus @default(DRAFT)
|
||||
|
||||
Reference in New Issue
Block a user