@@ -154,23 +154,56 @@ export function BatchUploadClient({ projects }: BatchUploadClientProps) {
|
||||
}));
|
||||
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
fd.append("action", item.status);
|
||||
fd.append("shotId", item.shotId!);
|
||||
fd.append("projectId", projectId);
|
||||
if (item.taskId) fd.append("taskId", item.taskId);
|
||||
if (item.fallbackTaskId) fd.append("fallbackTaskId", item.fallbackTaskId);
|
||||
if (item.newTaskTitle) fd.append("newTaskTitle", item.newTaskTitle);
|
||||
if (item.status === "update-highres") {
|
||||
// MOV high-res files: use XHR so the browser streams the file from
|
||||
// disk chunk-by-chunk, matching the behaviour of HighResUploadDialog
|
||||
// which is known to work reliably for large files.
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
fd.append("action", "update-highres");
|
||||
fd.append("shotId", item.shotId!);
|
||||
fd.append("projectId", projectId);
|
||||
|
||||
const res = await fetch("/api/batch-upload/upload", {
|
||||
method: "POST",
|
||||
body: fd,
|
||||
});
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/api/batch-upload/upload");
|
||||
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({ error: "Upload failed" }));
|
||||
throw new Error(data.error ?? "Upload failed");
|
||||
xhr.addEventListener("load", () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
resolve();
|
||||
} else {
|
||||
try {
|
||||
const json = JSON.parse(xhr.responseText) as { error?: string };
|
||||
reject(new Error(json.error ?? `HTTP ${xhr.status}`));
|
||||
} catch {
|
||||
reject(new Error(`HTTP ${xhr.status}`));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
xhr.addEventListener("error", () => reject(new Error("Network error")));
|
||||
xhr.addEventListener("abort", () => reject(new Error("Upload cancelled")));
|
||||
xhr.send(fd);
|
||||
});
|
||||
} else {
|
||||
// MP4 version uploads: existing fetch-based flow
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
fd.append("action", item.status);
|
||||
fd.append("shotId", item.shotId!);
|
||||
fd.append("projectId", projectId);
|
||||
if (item.taskId) fd.append("taskId", item.taskId);
|
||||
if (item.fallbackTaskId) fd.append("fallbackTaskId", item.fallbackTaskId);
|
||||
if (item.newTaskTitle) fd.append("newTaskTitle", item.newTaskTitle);
|
||||
|
||||
const res = await fetch("/api/batch-upload/upload", {
|
||||
method: "POST",
|
||||
body: fd,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({ error: "Upload failed" }));
|
||||
throw new Error(data.error ?? "Upload failed");
|
||||
}
|
||||
}
|
||||
|
||||
setUploadStates((prev) => ({
|
||||
|
||||
Reference in New Issue
Block a user