ed9f9b13c1
Deploy / deploy (push) Successful in 6m8s
Shot.clientCode already drove slates, overlay burn-ins and delivered file names, but the client portal — the one place the client actually reads — was still showing our internal codes. Task titles were the larger leak. They follow the house convention "UNG_106_010_020_cmp_TT_v004", so the internal code sat embedded in the string the client reads and copies, in three places on the shot list and again in the player header. Swapping only the heading would have left it on display directly underneath. lib/shot-code.ts resolves both: clientShotCode picks the alias when set, and clientTaskTitle swaps the code out of a title by substring, leaving a hand-edited title that does not carry the code untouched rather than guessing at it. Applied at the API boundary rather than at each render site, so the shot list, search, playlist labels, alt text, player header and every copy-to-clipboard button inherit it and nothing downstream has to remember which code it is holding. The internal code is no longer sent to the browser on these routes at all. Slack notifications deliberately keep the internal code: those go to our artists, who need the code that matches the comp and the SAN path. The two existing "clientCode || shotCode" expressions in preview.ts and deliveries.ts now use the same helper so slates, deliveries and the portal cannot drift apart. Shots with no clientCode are unchanged throughout. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
126 lines
4.5 KiB
TypeScript
126 lines
4.5 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { db } from "@/lib/db";
|
|
import { validateReviewToken } from "@/lib/review-auth";
|
|
import { clientShotCode, clientTaskTitle } from "@/lib/shot-code";
|
|
|
|
/** GET /api/client/[token]/versions/[versionId] — returns version + comments for client portal */
|
|
export async function GET(
|
|
req: NextRequest,
|
|
{ params }: { params: Promise<{ token: string; versionId: string }> }
|
|
) {
|
|
const { token, versionId } = await params;
|
|
const result = await validateReviewToken(token, req);
|
|
if (result.type === "requiresPassword") {
|
|
return NextResponse.json({ requiresPassword: true }, { status: 401 });
|
|
}
|
|
if (result.type === "invalid") {
|
|
return NextResponse.json({ error: "Invalid or expired review link" }, { status: 403 });
|
|
}
|
|
const session = result.session;
|
|
|
|
const version = await db.version.findUnique({
|
|
where: { id: versionId },
|
|
include: {
|
|
shot: {
|
|
include: {
|
|
project: { select: { id: true, name: true, code: true } },
|
|
versions: {
|
|
orderBy: { versionNumber: "desc" },
|
|
select: {
|
|
id: true,
|
|
versionNumber: true,
|
|
approvalStatus: true,
|
|
isLatest: true,
|
|
fps: true,
|
|
duration: true,
|
|
createdAt: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
task: {
|
|
include: {
|
|
project: { select: { id: true, name: true, code: true } },
|
|
shot: { select: { id: true, shotCode: true, clientCode: true, highResKey: true, highResFilename: true } },
|
|
asset: { select: { assetCode: true, name: true } },
|
|
},
|
|
},
|
|
artist: { select: { id: true, name: true, image: true, email: true } },
|
|
approvals: {
|
|
orderBy: { createdAt: "desc" },
|
|
include: { user: { select: { id: true, name: true } } },
|
|
},
|
|
},
|
|
});
|
|
|
|
// Resolve project: from shot or from task
|
|
const projectId = version?.shot?.projectId ?? version?.task?.projectId;
|
|
|
|
if (!version || projectId !== session.projectId) {
|
|
return NextResponse.json({ error: "Version not found" }, { status: 404 });
|
|
}
|
|
|
|
// For task-only versions (no shot), require explicit client sharing
|
|
if (!version.shot && !version.isClientVisible) {
|
|
return NextResponse.json({ error: "Version not found" }, { status: 404 });
|
|
}
|
|
|
|
const comments = await db.comment.findMany({
|
|
where: { versionId },
|
|
orderBy: { frameNumber: "asc" },
|
|
include: {
|
|
author: { select: { id: true, name: true, image: true, email: true } },
|
|
replies: {
|
|
orderBy: { createdAt: "asc" },
|
|
include: {
|
|
author: { select: { id: true, name: true, image: true, email: true } },
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
// Resolve the shot that has the high-res file (comes from version.shot OR version.task.shot)
|
|
const highResShot = version.shot ?? (version.task as any)?.shot ?? null;
|
|
|
|
// The shot the title and breadcrumb are drawn from — either relation.
|
|
const namingShot = version.shot ?? ((version.task as any)?.shot ?? null);
|
|
|
|
const serializedVersion = {
|
|
...version,
|
|
fileSize: version.fileSize?.toString() ?? null,
|
|
// Top-level high-res fields so the client works for both shot and task versions
|
|
hasHighRes: !!(highResShot?.highResKey),
|
|
highResShotId: highResShot?.highResKey ? (highResShot.id ?? null) : null,
|
|
highResFilename: highResShot?.highResFilename ?? null,
|
|
// Expose only whether a high-res file exists on the shot relation, never the storage key
|
|
shot: version.shot
|
|
? {
|
|
...version.shot,
|
|
shotCode: clientShotCode(version.shot),
|
|
clientCode: undefined,
|
|
hasHighRes: !!version.shot.highResKey,
|
|
highResFilename: version.shot.highResFilename ?? null,
|
|
highResKey: undefined,
|
|
}
|
|
: null,
|
|
// Task titles carry the shot code by convention, so the player header gets
|
|
// the same swap as the shot list (lib/shot-code.ts).
|
|
task: version.task
|
|
? {
|
|
...version.task,
|
|
title: namingShot ? clientTaskTitle(version.task.title, namingShot) : version.task.title,
|
|
shot: (version.task as any)?.shot
|
|
? {
|
|
...((version.task as any).shot),
|
|
shotCode: clientShotCode((version.task as any).shot),
|
|
clientCode: undefined,
|
|
highResKey: undefined, // strip storage key
|
|
}
|
|
: null,
|
|
}
|
|
: null,
|
|
};
|
|
|
|
return NextResponse.json({ version: serializedVersion, comments });
|
|
}
|