From c1180d6f9cf6c4caa5196cf80886ad265c8d0dfd Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 2 Feb 2024 22:46:24 +0000 Subject: [PATCH] up2k: include inflight bytes in eta calculation; much more accurate total-ETA when uploading with many connections and/or uploading huge files to really slow servers the titlebar % still only does actually confirmed bytes, partially because that makes sense, partially because that's what happened by accident --- copyparty/web/up2k.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index aa831248..701248f4 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -895,6 +895,7 @@ function up2k_init(subtle) { "bytes": { "total": 0, "hashed": 0, + "inflight": 0, "uploaded": 0, "finished": 0 }, @@ -1543,17 +1544,21 @@ function up2k_init(subtle) { if (uc.fsearch) t.push(['u2etat', st.bytes.hashed, st.bytes.hashed, st.time.hashing]); } + + var b_up = st.bytes.inflight + st.bytes.uploaded, + b_fin = st.bytes.inflight + st.bytes.finished; + if (nsend) { st.time.uploading += td; - t.push(['u2etau', st.bytes.uploaded, st.bytes.finished, st.time.uploading]); + t.push(['u2etau', b_up, b_fin, st.time.uploading]); } if ((nhash || nsend) && !uc.fsearch) { - if (!st.bytes.finished) { + if (!b_fin) { ebi('u2etat').innerHTML = L.u_etaprep; } else { st.time.busy += td; - t.push(['u2etat', st.bytes.finished, st.bytes.finished, st.time.busy]); + t.push(['u2etat', b_fin, b_fin, st.time.busy]); } } for (var a = 0; a < t.length; a++) { @@ -2539,6 +2544,7 @@ function up2k_init(subtle) { cdr = t.size; var orz = function (xhr) { + st.bytes.inflight -= xhr.bsent; var txt = unpre((xhr.response && xhr.response.err) || xhr.responseText); if (txt.indexOf('upload blocked by x') + 1) { apop(st.busy.upload, upt); @@ -2583,7 +2589,10 @@ function up2k_init(subtle) { btot = Math.floor(st.bytes.total / 1024 / 1024); xhr.upload.onprogress = function (xev) { - pvis.prog(t, npart, xev.loaded); + var nb = xev.loaded; + st.bytes.inflight += nb - xhr.bsent; + xhr.bsent = nb; + pvis.prog(t, npart, nb); }; xhr.onload = function (xev) { try { orz(xhr); } catch (ex) { vis_exh(ex + '', 'up2k.js', '', '', ex); } @@ -2592,6 +2601,8 @@ function up2k_init(subtle) { if (crashed) return; + st.bytes.inflight -= (xhr.bsent || 0); + if (!toast.visible) toast.warn(9.98, L.u_cuerr.format(npart, Math.ceil(t.size / chunksize), t.name), t); @@ -2608,6 +2619,7 @@ function up2k_init(subtle) { if (xhr.overrideMimeType) xhr.overrideMimeType('Content-Type', 'application/octet-stream'); + xhr.bsent = 0; xhr.responseType = 'text'; xhr.send(t.fobj.slice(car, cdr)); }