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"> <div class="lib-header">
<input type="text" id="lib-search" placeholder="FILTER LIBRARY..." onkeyup="filterLibrary()"> <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> <button class="refresh-btn" onclick="refreshLibrary()" title="Refresh Library">REFRESH</button>
</div> </div>

View File

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