fix(bulk-upload): skip navigation when any chunk fails to upload

goto('/documents') fired unconditionally, discarding error chips and
leaving the user with no feedback on which files failed. Now only
navigates when hadErrors is false after all chunks complete.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-24 21:18:17 +02:00
committed by marcel
parent 4229e952fb
commit fc118f7032
2 changed files with 26 additions and 5 deletions

View File

@@ -92,6 +92,7 @@ async function save() {
}
chunkProgress = { done: 0, total: chunks.length };
let hadErrors = false;
for (let i = 0; i < chunks.length; i++) {
const chunk = chunks[i];
const formData = new FormData();
@@ -106,6 +107,7 @@ async function save() {
formData.append('metadata', new Blob([JSON.stringify(metadata)], { type: 'application/json' }));
const res = await fetch('/api/documents/quick-upload', { method: 'POST', body: formData });
if (!res.ok) {
hadErrors = true;
const body = await res.json().catch(() => ({ errors: [] }));
const errorCount = (body.errors ?? []).length;
for (let j = 0; j < errorCount && j < chunk.length; j++) {
@@ -115,7 +117,7 @@ async function save() {
}
chunkProgress = { done: i + 1, total: chunks.length };
}
goto('/documents');
if (!hadErrors) goto('/documents');
}
</script>