From c76baec1c1c1a70008d802c774210109b6b34f39 Mon Sep 17 00:00:00 2001 From: xenofem Date: Mon, 23 May 2022 20:44:22 -0400 Subject: [PATCH] nicer display of upload progress info --- static/css/transbeam.css | 21 ++++++++++++++++++++ static/index.html | 7 ++++++- static/js/upload.js | 41 ++++++++++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/static/css/transbeam.css b/static/css/transbeam.css index 1ca0dfe..a8ea0ae 100644 --- a/static/css/transbeam.css +++ b/static/css/transbeam.css @@ -27,6 +27,27 @@ body { margin: 10px auto; } +#progress { + display: flex; + align-items: center; + column-gap: 15px; + row-gap: 5px; + flex-wrap: wrap; +} + +#progress_percentage { + flex-grow: 1; +} +#progress_size { + flex-grow: 3; +} +#progress_rate { + flex-grow: 2; +} +#progress_eta { + flex-grow: 3; +} + #progress_bar { height: 20px; border-radius: 10px; diff --git a/static/index.html b/static/index.html index 58ecd49..e930318 100644 --- a/static/index.html +++ b/static/index.html @@ -71,7 +71,12 @@
Link copied!
-
+
+
+
+
+
+
diff --git a/static/js/upload.js b/static/js/upload.js index d45ec86..e46da6c 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -1,7 +1,7 @@ const FILE_CHUNK_SIZE = 16384; const MAX_FILES = 256; const SAMPLE_WINDOW = 100; -const STALL_THRESHOLD = 1; +const STALL_THRESHOLD = 1000; let files = []; @@ -22,7 +22,11 @@ let fileList; let uploadButton; let lifetimeInput; let downloadCode; -let progress; + +let progressPercentage; +let progressSize; +let progressRate; +let progressEta; let progressBar; document.addEventListener('DOMContentLoaded', () => { @@ -34,7 +38,10 @@ document.addEventListener('DOMContentLoaded', () => { uploadButton = document.getElementById('upload_button'); lifetimeInput = document.getElementById('lifetime'); downloadCode = document.getElementById('download_code'); - progress = document.getElementById('progress'); + progressPercentage = document.getElementById('progress_percentage'); + progressSize = document.getElementById('progress_size'); + progressRate = document.getElementById('progress_rate'); + progressEta = document.getElementById('progress_eta'); progressBar = document.getElementById('progress_bar'); fetch('/upload/limits.json') @@ -278,22 +285,28 @@ function updateProgress() { } else { percentage = `${(bytesSent*100/totalBytes).toFixed(1)}%`; } - let progressString = `${percentage} - ${displaySize(bytesSent)}/${displaySize(totalBytes)}`; + progressPercentage.textContent = percentage; + + progressSize.textContent = `${displaySize(bytesSent)}/${displaySize(totalBytes)}`; + if (timestamps.length >= 2) { const start = timestamps.at(0); const end = timestamps.at(-1); - if (end[0] - start[0] > 0) { - const rate = (end[1] - start[1])/(end[0] - start[0]); - if (rate > STALL_THRESHOLD) { - // Use the value from timestamps rather than bytesSent to avoid awkward UI thrashing - const remaining = (totalBytes - end[1]) / rate; - progressString += ` - ${displaySize(rate)}/s - ${displayTime(remaining)} remaining`; - } else { - progressString += " - stalled"; - } + const rate = (end[1] - start[1])/(end[0] - start[0]); + progressRate.textContent = `${displaySize(rate)}/s`; + + if (rate > STALL_THRESHOLD) { + // Use the value from timestamps rather than bytesSent to avoid awkward UI thrashing + const remaining = (totalBytes - end[1]) / rate; + progressEta.textContent = `${displayTime(remaining)} remaining`; + } else { + progressEta.textContent = "stalled"; } + } else { + progressRate.textContent = "???B/s"; + progressEta.textContent = "??? remaining"; } - progress.textContent = progressString; + progressBar.style.backgroundSize = percentage; const fileEntries = Array.from(fileList.children);