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>
60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { randomUUID } from "crypto";
|
|
import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth";
|
|
import { toErrorResponse, PipelineError } from "@/lib/render-pipeline/errors";
|
|
import { db } from "@/lib/db";
|
|
import { generateHetznerPresignedUploadUrl, sanitizeFileName } from "@/lib/storage";
|
|
|
|
// ── POST /api/ext/render/jobs/{jobId}/artifact-presign (E20) ─────────────────
|
|
//
|
|
// Presigned upload URL for worker artifacts. Kinds map to the existing object
|
|
// storage folder layout: preview → videos/, thumbnail → image/,
|
|
// metadata/log → renders/, highres (the delivery MOV) → highres/ beside the
|
|
// manually uploaded High Res files.
|
|
|
|
const KIND_FOLDERS: Record<string, string> = {
|
|
preview: "videos",
|
|
thumbnail: "image",
|
|
metadata: "renders",
|
|
log: "renders",
|
|
highres: "highres",
|
|
};
|
|
|
|
export async function POST(
|
|
req: NextRequest,
|
|
{ params }: { params: Promise<{ jobId: string }> }
|
|
) {
|
|
if (!isExtAuthorized(req)) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
const { jobId } = await params;
|
|
let body: { machineId?: string; kind?: string; fileName?: string; contentType?: string };
|
|
try {
|
|
body = await req.json();
|
|
} catch {
|
|
return NextResponse.json({ error: "Invalid JSON" }, { status: 400 });
|
|
}
|
|
try {
|
|
if (!body.machineId) throw new PipelineError(400, "machineId is required");
|
|
if (!body.fileName) throw new PipelineError(400, "fileName is required");
|
|
if (!body.contentType) throw new PipelineError(400, "contentType is required");
|
|
const folder = KIND_FOLDERS[body.kind ?? ""];
|
|
if (!folder) {
|
|
throw new PipelineError(422, `kind must be one of: ${Object.keys(KIND_FOLDERS).join(", ")}`);
|
|
}
|
|
|
|
const job = await db.renderJob.findUnique({ where: { id: jobId }, select: { machineId: true } });
|
|
if (!job) throw new PipelineError(404, "Render job not found");
|
|
if (job.machineId !== body.machineId) {
|
|
throw new PipelineError(409, "Job is not held by this machine (lease reassigned?)");
|
|
}
|
|
|
|
const key = `${folder}/${randomUUID()}-${sanitizeFileName(body.fileName)}`;
|
|
const presignedUrl = await generateHetznerPresignedUploadUrl(key, body.contentType);
|
|
return NextResponse.json({ presignedUrl, key, url: `/api/files/${key}` });
|
|
} catch (err) {
|
|
const { body: errBody, status } = toErrorResponse(err);
|
|
return NextResponse.json(errBody, { status });
|
|
}
|
|
}
|