Fix upload error handling; log 413 nginx size limit clearly

This commit is contained in:
ComputerTech 2026-03-10 19:13:39 +00:00
parent 1fa6887efd
commit 43a3e692fc
2 changed files with 30 additions and 27 deletions

View File

@ -71,7 +71,6 @@
<div class="lib-header">
<input type="text" id="lib-search" placeholder="FILTER LIBRARY..." onkeyup="filterLibrary()">
<button class="folder-btn" onclick="openFolderPicker()" title="Choose Folder">OPEN</button>
<button class="refresh-btn" onclick="refreshLibrary()" title="Refresh Library">REFRESH</button>
</div>

View File

@ -1572,44 +1572,48 @@ async function handleFileUpload(event) {
progressRow.appendChild(barWrap);
progressContainer.appendChild(progressRow);
try {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
return new Promise((resolve) => {
const xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
xhr.upload.onprogress = (e) => {
if (e.lengthComputable) {
const percent = (e.loaded / e.total) * 100;
barInner.style.width = percent + '%';
}
};
xhr.upload.onprogress = (e) => {
if (e.lengthComputable) {
const percent = (e.loaded / e.total) * 100;
barInner.style.width = percent + '%';
}
};
xhr.onload = () => {
if (xhr.status === 200) {
xhr.onload = () => {
if (xhr.status === 200) {
try {
const result = JSON.parse(xhr.responseText);
if (result.success) {
barInner.style.background = '#00ff88';
resolve();
} else {
barInner.style.background = '#ff4444';
reject(new Error(result.error));
nameSpan.title = result.error || 'Upload failed';
console.error(`[UPLOAD] ${file.name}: ${result.error}`);
}
} else {
} catch (e) {
barInner.style.background = '#ff4444';
reject(new Error(`HTTP ${xhr.status}`));
console.error(`[UPLOAD] Bad response for ${file.name}`);
}
};
xhr.onerror = () => {
} else {
barInner.style.background = '#ff4444';
reject(new Error('Network error'));
};
nameSpan.title = `HTTP ${xhr.status}`;
console.error(`[UPLOAD] ${file.name}: HTTP ${xhr.status}${xhr.status === 413 ? ' — file too large (nginx limit)' : ''}`);
}
resolve(); // Always resolve so other uploads continue
};
xhr.send(formData);
});
} catch (error) {
console.error(`[ERROR] Upload error: ${error}`);
}
xhr.onerror = () => {
barInner.style.background = '#ff4444';
console.error(`[UPLOAD] ${file.name}: Network error`);
resolve();
};
xhr.send(formData);
});
});
// Run uploads in parallel (limited to 3 at a time for stability if needed, but let's try all)