From d3db6d296f9e04fbc912124dca9be43908305b1a Mon Sep 17 00:00:00 2001
From: ed
Date: Thu, 1 Feb 2024 21:41:48 +0000
Subject: [PATCH 1/7] disable mkdir and new-doc buttons if no name is provided
also fixes toast.hide() unintentionally stopping events from bubbling
---
copyparty/web/browser.js | 36 +++++++++++++++++++++++++++++++++++-
copyparty/web/util.js | 7 ++++++-
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js
index 9d045717..9301f1c0 100644
--- a/copyparty/web/browser.js
+++ b/copyparty/web/browser.js
@@ -332,6 +332,8 @@ var Ls = {
"fp_confirm": "move these {0} items here?",
"fp_etab": 'failed to read clipboard from other browser tab',
+ "mk_noname": "type a name into the text field on the left before you do that :p",
+
"tv_load": "Loading text document:\n\n{0}\n\n{1}% ({2} of {3} MiB loaded)",
"tv_xe1": "could not load textfile:\n\nerror ",
"tv_xe2": "404, file not found",
@@ -821,6 +823,8 @@ var Ls = {
"fp_confirm": "flytt disse {0} filene hit?",
"fp_etab": 'kunne ikke lese listen med filer ifra den andre nettleserfanen',
+ "mk_noname": "skriv inn et navn i tekstboksen til venstre fΓΈrst :p",
+
"tv_load": "Laster inn tekstfil:\n\n{0}\n\n{1}% ({2} av {3} MiB lastet ned)",
"tv_xe1": "kunne ikke laste tekstfil:\n\nfeil ",
"tv_xe2": "404, Fil ikke funnet",
@@ -7267,6 +7271,28 @@ var msel = (function () {
})();
+(function () {
+ if (!window.FormData)
+ return;
+
+ var form = QS('#op_new_md>form'),
+ tb = QS('#op_new_md input[name="name"]');
+
+ form.onsubmit = function (e) {
+ if (tb.value) {
+ if (toast.tag == L.mk_noname)
+ toast.hide();
+
+ return true;
+ }
+
+ ev(e);
+ toast.err(10, L.mk_noname, L.mk_noname);
+ return false;
+ };
+})();
+
+
(function () {
if (!window.FormData)
return;
@@ -7280,8 +7306,16 @@ var msel = (function () {
form.onsubmit = function (e) {
ev(e);
- clmod(sf, 'vis', 1);
var dn = tb.value;
+ if (!dn) {
+ toast.err(10, L.mk_noname, L.mk_noname);
+ return false;
+ }
+
+ if (toast.tag == L.mk_noname || toast.tag == L.fd_xe1)
+ toast.hide();
+
+ clmod(sf, 'vis', 1);
sf.textContent = 'creating "' + dn + '"...';
var fd = new FormData();
diff --git a/copyparty/web/util.js b/copyparty/web/util.js
index dc548cab..6ea920b2 100644
--- a/copyparty/web/util.js
+++ b/copyparty/web/util.js
@@ -1455,7 +1455,9 @@ var toast = (function () {
}
r.hide = function (e) {
- ev(e);
+ if (this === ebi('toastc'))
+ ev(e);
+
unscroll();
clearTimeout(te);
clmod(obj, 'vis');
@@ -1985,6 +1987,9 @@ function xhrchk(xhr, prefix, e404, lvl, tag) {
if (xhr.status < 400 && xhr.status >= 200)
return true;
+ if (tag === undefined)
+ tag = prefix;
+
var errtxt = (xhr.response && xhr.response.err) || xhr.responseText,
fun = toast[lvl || 'err'],
is_cf = /[Cc]loud[f]lare|>Just a mo[m]ent|#cf-b[u]bbles|Chec[k]ing your br[o]wser|\/chall[e]nge-platform|"chall[e]nge-error|nable Ja[v]aScript and cook/.test(errtxt);
From c1180d6f9cf6c4caa5196cf80886ad265c8d0dfd Mon Sep 17 00:00:00 2001
From: ed
Date: Fri, 2 Feb 2024 22:46:24 +0000
Subject: [PATCH 2/7] 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));
}
From a17c267d87fbc581fcbe654d532e52cc7197c47b Mon Sep 17 00:00:00 2001
From: ed
Date: Fri, 2 Feb 2024 23:16:50 +0000
Subject: [PATCH 3/7] bbox: unload pics/vids from DOM; closes #71
videos unloaded correctly when switching between files, but not when
closing the lightbox while playing a video and then clicking another
now, only media within the preload window (+/- 2 from current file)
is kept loaded into DOM, everything else gets ejected, both on
navigation and when closing the lightbox
---
copyparty/web/baguettebox.js | 56 ++++++++++++++++++++++++++++++++----
1 file changed, 50 insertions(+), 6 deletions(-)
diff --git a/copyparty/web/baguettebox.js b/copyparty/web/baguettebox.js
index 3a173f8a..39a9c8d1 100644
--- a/copyparty/web/baguettebox.js
+++ b/copyparty/web/baguettebox.js
@@ -615,7 +615,43 @@ window.baguetteBox = (function () {
documentLastFocus && documentLastFocus.focus();
isOverlayVisible = false;
- }, 500);
+ unvid();
+ unfig();
+ }, 250);
+ }
+
+ function unvid(keep) {
+ var vids = QSA('#bbox-overlay video');
+ for (var a = vids.length - 1; a >= 0; a--) {
+ var v = vids[a];
+ if (v == keep)
+ continue;
+
+ v.src = '';
+ v.load();
+
+ var p = v.parentNode;
+ p.removeChild(v);
+ p.parentNode.removeChild(p);
+ }
+ }
+
+ function unfig(keep) {
+ var figs = QSA('#bbox-overlay figure'),
+ npre = options.preload || 0,
+ k = [];
+
+ if (keep === undefined)
+ keep = -9;
+
+ for (var a = keep - npre; a <= keep + npre; a++)
+ k.push('bbox-figure-' + a);
+
+ for (var a = figs.length - 1; a >= 0; a--) {
+ var f = figs[a];
+ if (!has(k, f.getAttribute('id')))
+ f.parentNode.removeChild(f);
+ }
}
function loadImage(index, callback) {
@@ -708,6 +744,7 @@ window.baguetteBox = (function () {
}
function show(index, gallery) {
+ gallery = gallery || currentGallery;
if (!isOverlayVisible && index >= 0 && index < gallery.length) {
prepareOverlay(gallery, options);
showOverlay(index);
@@ -720,12 +757,10 @@ window.baguetteBox = (function () {
if (index >= imagesElements.length)
return bounceAnimation('right');
- var v = vid();
- if (v) {
- v.src = '';
- v.load();
- v.parentNode.removeChild(v);
+ try {
+ vid().pause();
}
+ catch (ex) { }
currentIndex = index;
loadImage(currentIndex, function () {
@@ -734,6 +769,15 @@ window.baguetteBox = (function () {
});
updateOffset();
+ if (options.animation == 'none')
+ unvid(vid());
+ else
+ setTimeout(function () {
+ unvid(vid());
+ }, 100);
+
+ unfig(index);
+
if (options.onChange)
options.onChange(currentIndex, imagesElements.length);
From c354a38b4ccbc2c67a76c57a5d017227c00c5e0a Mon Sep 17 00:00:00 2001
From: ed
Date: Fri, 2 Feb 2024 23:46:00 +0000
Subject: [PATCH 4/7] up2k: warn about browser cap on num connections
---
copyparty/__main__.py | 2 +-
copyparty/web/browser.js | 2 ++
copyparty/web/ui.css | 4 ++++
copyparty/web/up2k.js | 3 +++
4 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/copyparty/__main__.py b/copyparty/__main__.py
index 3566aff1..f7161235 100755
--- a/copyparty/__main__.py
+++ b/copyparty/__main__.py
@@ -888,7 +888,7 @@ def add_upload(ap):
ap2.add_argument("--df", metavar="GiB", type=float, default=0, help="ensure \033[33mGiB\033[0m free disk space by rejecting upload requests")
ap2.add_argument("--sparse", metavar="MiB", type=int, default=4, help="windows-only: minimum size of incoming uploads through up2k before they are made into sparse files")
ap2.add_argument("--turbo", metavar="LVL", type=int, default=0, help="configure turbo-mode in up2k client; [\033[32m-1\033[0m] = forbidden/always-off, [\033[32m0\033[0m] = default-off and warn if enabled, [\033[32m1\033[0m] = default-off, [\033[32m2\033[0m] = on, [\033[32m3\033[0m] = on and disable datecheck")
- ap2.add_argument("--u2j", metavar="JOBS", type=int, default=2, help="web-client: number of file chunks to upload in parallel; 1 or 2 is good for low-latency (same-country) connections, 4-8 for android clients, 16-32 for cross-atlantic (max=64)")
+ ap2.add_argument("--u2j", metavar="JOBS", type=int, default=2, help="web-client: number of file chunks to upload in parallel; 1 or 2 is good for low-latency (same-country) connections, 4-8 for android clients, 16 for cross-atlantic (max=64)")
ap2.add_argument("--u2sort", metavar="TXT", type=u, default="s", help="upload order; [\033[32ms\033[0m]=smallest-first, [\033[32mn\033[0m]=alphabetical, [\033[32mfs\033[0m]=force-s, [\033[32mfn\033[0m]=force-n -- alphabetical is a bit slower on fiber/LAN but makes it easier to eyeball if everything went fine")
ap2.add_argument("--write-uplog", action="store_true", help="write POST reports to textfiles in working-directory")
diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js
index 9301f1c0..98c14d0c 100644
--- a/copyparty/web/browser.js
+++ b/copyparty/web/browser.js
@@ -465,6 +465,7 @@ var Ls = {
"u_emtleakf": 'try the following:\n
\nPS: firefox will hopefully have a bugfix at some point',
"u_s404": "not found on server",
"u_expl": "explain",
+ "u_maxconn": "most browsers limit this to 6, but firefox lets you raise it with F5
to refresh the pageπ₯
(potato) in the upload UIconnections-per-server
in about:config
",
"u_tu": '
WARNING: turbo enabled, client may not detect and resume incomplete uploads; see turbo-button tooltip
', "u_ts": 'WARNING: turbo enabled, search results can be incorrect; see turbo-button tooltip
', "u_turbo_c": "turbo is disabled in server config", @@ -956,6 +957,7 @@ var Ls = { "u_emtleakf": 'prΓΈver fΓΈlgende:\nπ₯
("enkelt UI") i opplasterenconnections-per-server
in about:config
",
"u_tu": 'ADVARSEL: turbo er pΓ₯, avbrutte opplastninger vil muligens ikke oppdages og gjenopptas; hold musepekeren over turbo-knappen for mer info
', "u_ts": 'ADVARSEL: turbo er pΓ₯, sΓΈkeresultater kan vΓ¦re feil; hold musepekeren over turbo-knappen for mer info
', "u_turbo_c": "turbo er deaktivert i serverkonfigurasjonen", diff --git a/copyparty/web/ui.css b/copyparty/web/ui.css index 72b36a1d..e27030ec 100644 --- a/copyparty/web/ui.css +++ b/copyparty/web/ui.css @@ -147,6 +147,10 @@ html { #toast.err #toastc { background: #d06; } +#toast code { + padding: 0 .2em; + background: rgba(0,0,0,0.2); +} #tth { color: #fff; background: #111; diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 701248f4..5386d5eb 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -2720,6 +2720,9 @@ function up2k_init(subtle) { if (parallel_uploads > 16) parallel_uploads = 16; + if (parallel_uploads > 7) + toast.warn(10, L.u_maxconn); + obj.value = parallel_uploads; bumpthread({ "target": 1 }); } From b1cf588452d40266e1d5686b57406131ee34b656 Mon Sep 17 00:00:00 2001 From: ed