9660cdc21c
Deploy / deploy (push) Successful in 3m23s
Worker 1.7.0 (preview.highQuality, default on) now, after the AE render: - encodes a High quality MP4 from the delivery MOV (full-res H.264 High, CRF 14 capped at 100 Mbps) -> Version.hqFileUrl - uploads the MOV itself -> Version.highResKey/Filename/Size Both best-effort (the preview never fails over them), with a lease keep-alive during the long encode/uploads; the export timeline records what was attached. Player: HQ switch when a High quality source exists; keeps frame, play state, speed and zoom, remembered per browser, falls back to Standard if the file won't load. ProRes itself stays download-only (browser support). Downloads: the client portal's High Res button serves the version's ProRes (client-code filename), falling back to the shot's manual file; staff get a ProRes button on the review page. Housekeeping (lib/render-pipeline/high-res.ts): HQ MP4 + ProRes are kept while a version is latest, client-shared, approved or younger than preview.highResRetentionDays (14); otherwise deleted from storage. Runs per task after finalize and hourly from the reaper; deleting a version or a reslate removes its files. The Standard MP4 is never touched. Also: ProRes/Handles top-bar buttons go icon-only below lg so they don't overlap the version selector. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
144 lines
5.5 KiB
TypeScript
144 lines
5.5 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { db } from "@/lib/db";
|
|
import { validateReviewToken, findReviewUser, ownsComment } from "@/lib/review-auth";
|
|
import { clientHighResFilename, 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 commentRows = 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 } },
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
// Which notes this reviewer may edit or delete. Read-only: opening a review
|
|
// link should not create the guest User, so a session that has never posted
|
|
// simply owns nothing. The edit/delete route re-checks this — the flag drives
|
|
// the UI, it does not grant anything.
|
|
const reviewUser = await findReviewUser(session, token);
|
|
const comments = commentRows.map((c) => ({
|
|
...c,
|
|
canEdit: ownsComment(c, reviewUser?.id),
|
|
}));
|
|
|
|
// 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);
|
|
|
|
// High Res: this version's own ProRes (uploaded by the render worker) wins;
|
|
// the shot's manually uploaded file is the fallback for older versions.
|
|
const versionHighRes = !!version.highResKey;
|
|
const serializedVersion = {
|
|
...version,
|
|
fileSize: version.fileSize?.toString() ?? null,
|
|
highResKey: undefined, // never expose a storage key
|
|
highResSize: version.highResSize?.toString() ?? null,
|
|
// Top-level high-res fields so the client works for both shot and task versions
|
|
hasHighRes: versionHighRes || !!(highResShot?.highResKey),
|
|
highResSource: versionHighRes ? "version" : highResShot?.highResKey ? "shot" : null,
|
|
highResShotId: !versionHighRes && highResShot?.highResKey ? (highResShot.id ?? null) : null,
|
|
highResFilename: versionHighRes
|
|
? clientHighResFilename(version.highResFilename ?? "high-res.mov", namingShot)
|
|
: 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 });
|
|
}
|