From 136c0fdc2b74ca57340f547e9a5827278519ebe8 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 5 Feb 2024 19:17:36 +0000 Subject: [PATCH] detect reverse-proxies stripping URL params: if a reverseproxy decides to strip away URL parameters, show an appropriate error-toast instead of silently entering a bad state someone on discord ended up in an infinite page-reload loop since the js would try to recover by fully navigating to the requested dir if `?ls` failed, which wouldn't do any good anyways if the dir in question is the initial dir to display --- copyparty/web/browser.js | 13 ++++++++----- copyparty/web/util.js | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 98c14d0c..b84f32e3 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -5830,7 +5830,7 @@ var treectl = (function () { var res = JSON.parse(this.responseText); } catch (ex) { - return; + return toast.err(30, "bad ?tree reply;\nexpected json, got this:\n\n" + esc(this.responseText + '')); } rendertree(res, this.ts, this.top, this.dst, this.rst); } @@ -5995,7 +5995,7 @@ var treectl = (function () { thegrid.setvis(true); } - r.reqls = function (url, hpush, back) { + r.reqls = function (url, hpush, back, hydrate) { if (IE && !history.pushState) return window.location = url; @@ -6003,6 +6003,7 @@ var treectl = (function () { xhr.top = url.split('?')[0]; xhr.back = back xhr.hpush = hpush; + xhr.hydrate = hydrate; xhr.ts = Date.now(); xhr.open('GET', xhr.top + '?ls' + (r.dots ? '&dots' : ''), true); xhr.onload = xhr.onerror = recvls; @@ -6049,8 +6050,10 @@ var treectl = (function () { var res = JSON.parse(this.responseText); } catch (ex) { - location = this.top; - return; + if (!this.hydrate) + location = this.top; + + return toast.err(30, "bad ?ls reply;\nexpected json, got this:\n\n" + esc(this.responseText + '')); } if (r.chk_index_html(this.top, res)) @@ -6272,7 +6275,7 @@ var treectl = (function () { xhr.send(); r.ls_cb = showfile.addlinks; - return r.reqls(get_evpath(), false); + return r.reqls(get_evpath(), false, undefined, true); } var top = get_evpath(); diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 6ea920b2..057b8ad9 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1470,6 +1470,8 @@ var toast = (function () { }; r.show = function (cl, sec, txt, tag) { + txt = (txt + '').slice(0, 16384); + var same = r.visible && txt == r.p_txt && r.p_sec == sec, delta = Date.now() - r.p_t;