CORS UPloads
Deploy / deploy (push) Successful in 3m5s

This commit is contained in:
twotalesanimation
2026-07-22 00:03:02 +02:00
parent 519fe2ad33
commit 15fda1ec44
4 changed files with 194 additions and 60 deletions
+45 -31
View File
@@ -37,13 +37,56 @@ export async function POST(
const fallbackTaskId = formData.get("fallbackTaskId") as string | null;
const newTaskTitle = (formData.get("newTaskTitle") as string | null) ?? "";
if (!file || !action || !shotId || !projectId) {
if (!action || !shotId || !projectId) {
return NextResponse.json(
{ error: "Missing required fields: file, action, shotId, projectId" },
{ error: "Missing required fields: action, shotId, projectId" },
{ status: 400 }
);
}
// ── High-res (.mov) — file was uploaded directly to Hetzner via presigned URL ──
// The file never passes through this server or the Nginx proxy, avoiding
// HTTP 413 errors caused by client_max_body_size limits.
if (action === "update-highres") {
const preUploadedKey = formData.get("key") as string | null;
const preUploadedFileName = formData.get("fileName") as string | null;
if (!preUploadedKey || !preUploadedFileName) {
return NextResponse.json(
{ error: "key and fileName are required for update-highres" },
{ status: 400 }
);
}
const shot = await db.shot.findUnique({
where: { id: shotId },
select: { id: true, highResKey: true },
});
if (!shot) {
return NextResponse.json({ error: "Shot not found" }, { status: 404 });
}
if (shot.highResKey) {
await deleteFromHetzner(shot.highResKey).catch(() => {});
}
await db.shot.update({
where: { id: shotId },
data: { highResKey: preUploadedKey, highResFilename: preUploadedFileName },
});
return NextResponse.json({
success: true,
action: "update-highres",
fileName: preUploadedFileName,
});
}
// For all other actions (MP4 version uploads) a file is required.
if (!file) {
return NextResponse.json({ error: "file is required" }, { status: 400 });
}
const buffer = Buffer.from(await file.arrayBuffer());
// Browsers (especially on Windows) often send an empty MIME type for .mov
@@ -55,35 +98,6 @@ export async function POST(
ext === "mp4" ? "video/mp4" :
"application/octet-stream");
// ── High-res (.mov) ───────────────────────────────────────────────────────
if (action === "update-highres") {
const shot = await db.shot.findUnique({
where: { id: shotId },
select: { id: true, highResKey: true },
});
if (!shot) {
return NextResponse.json({ error: "Shot not found" }, { status: 404 });
}
// Remove the previous high-res file if one exists
if (shot.highResKey) {
await deleteFromHetzner(shot.highResKey).catch(() => {});
}
const { key } = await uploadToHetzner(buffer, file.name, contentType, "highres");
await db.shot.update({
where: { id: shotId },
data: { highResKey: key, highResFilename: file.name },
});
return NextResponse.json({
success: true,
action: "update-highres",
fileName: file.name,
});
}
// ── Version upload (.mp4) ─────────────────────────────────────────────────
let resolvedTaskId: string;