Adjust progress bar
This commit is contained in:
@@ -4851,11 +4851,11 @@
|
|||||||
let batchOffset = 0;
|
let batchOffset = 0;
|
||||||
|
|
||||||
while (batchOffset < batchBuf.byteLength && ws.readyState === WebSocket.OPEN) {
|
while (batchOffset < batchBuf.byteLength && ws.readyState === WebSocket.OPEN) {
|
||||||
// Backpressure: yield once when the send buffer is full.
|
// Backpressure: yield when the send buffer builds up.
|
||||||
// A single zero-delay yield lets the browser flush the
|
// Keeps the ESP32 from being overwhelmed while avoiding
|
||||||
// WebSocket buffer without the ~4ms minimum of setTimeout.
|
// the ~4ms minimum of higher setTimeout values.
|
||||||
if (ws.bufferedAmount > WS_CHUNK_SIZE * 4) {
|
if (ws.bufferedAmount > WS_CHUNK_SIZE * 2) {
|
||||||
await new Promise(r => setTimeout(r, 0));
|
await new Promise(r => setTimeout(r, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ws.readyState !== WebSocket.OPEN) {
|
if (ws.readyState !== WebSocket.OPEN) {
|
||||||
@@ -4870,12 +4870,15 @@
|
|||||||
offset = batchEnd;
|
offset = batchEnd;
|
||||||
|
|
||||||
if (onProgress) {
|
if (onProgress) {
|
||||||
onProgress(offset, totalSize);
|
// Cap at 99% — 100% is shown only when server confirms DONE
|
||||||
|
const reported = Math.min(offset, Math.floor(totalSize * 0.99));
|
||||||
|
onProgress(reported, totalSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendingChunks = false;
|
sendingChunks = false;
|
||||||
console.log('[WS] All chunks sent, waiting for DONE');
|
console.log('[WS] All chunks sent, waiting for DONE');
|
||||||
|
if (onProgress) onProgress(totalSize, totalSize, 'saving');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[WS] Error sending chunks:', err);
|
console.error('[WS] Error sending chunks:', err);
|
||||||
sendingChunks = false;
|
sendingChunks = false;
|
||||||
@@ -5076,20 +5079,24 @@
|
|||||||
console.log(`[Upload] ${file.name} via ${uploadMethod}`);
|
console.log(`[Upload] ${file.name} via ${uploadMethod}`);
|
||||||
|
|
||||||
let uploadStartTime = 0;
|
let uploadStartTime = 0;
|
||||||
const onProgress = (loaded, total) => {
|
const onProgress = (loaded, total, state) => {
|
||||||
if (!uploadStartTime) uploadStartTime = Date.now();
|
if (!uploadStartTime) uploadStartTime = Date.now();
|
||||||
const uploadPercent = Math.round((loaded / total) * 100);
|
const uploadPercent = Math.round((loaded / total) * 100);
|
||||||
// If conversion succeeded, display goes from 50-100%, otherwise 0-100%
|
// If conversion succeeded, display goes from 50-100%, otherwise 0-100%
|
||||||
const displayPercent = conversionSucceeded ? 50 + Math.round(uploadPercent / 2) : uploadPercent;
|
const displayPercent = conversionSucceeded ? 50 + Math.round(uploadPercent / 2) : uploadPercent;
|
||||||
progressFill.style.width = displayPercent + '%';
|
progressFill.style.width = displayPercent + '%';
|
||||||
const prefix = conversionSucceeded ? 'Converting & uploading' : 'Uploading';
|
|
||||||
let speedText = '';
|
let speedText = '';
|
||||||
const elapsed = (Date.now() - uploadStartTime) / 1000;
|
const elapsed = (Date.now() - uploadStartTime) / 1000;
|
||||||
if (elapsed > 0.5 && loaded > 0) {
|
if (elapsed > 0.5 && loaded > 0) {
|
||||||
const kbps = (loaded / 1024) / elapsed;
|
const kbps = (loaded / 1024) / elapsed;
|
||||||
speedText = kbps >= 1024 ? ` — ${(kbps / 1024).toFixed(1)} MB/s` : ` — ${Math.round(kbps)} KB/s`;
|
speedText = kbps >= 1024 ? ` — ${(kbps / 1024).toFixed(1)} MB/s` : ` — ${Math.round(kbps)} KB/s`;
|
||||||
}
|
}
|
||||||
progressText.textContent = `${prefix} ${file.name} (${currentIndex + 1}/${files.length}) — ${uploadPercent}%${speedText}`;
|
if (state === 'saving') {
|
||||||
|
progressText.textContent = `Saving ${file.name} (${currentIndex + 1}/${files.length})...${speedText}`;
|
||||||
|
} else {
|
||||||
|
const prefix = conversionSucceeded ? 'Converting & uploading' : 'Uploading';
|
||||||
|
progressText.textContent = `${prefix} ${file.name} (${currentIndex + 1}/${files.length}) — ${uploadPercent}%${speedText}`;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onComplete = () => {
|
const onComplete = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user