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
This commit is contained in:
ed 2024-02-05 19:17:36 +00:00
parent cab999978e
commit 136c0fdc2b
2 changed files with 10 additions and 5 deletions

View file

@ -5830,7 +5830,7 @@ var treectl = (function () {
var res = JSON.parse(this.responseText); var res = JSON.parse(this.responseText);
} }
catch (ex) { catch (ex) {
return; return toast.err(30, "bad <code>?tree</code> reply;\nexpected json, got this:\n\n" + esc(this.responseText + ''));
} }
rendertree(res, this.ts, this.top, this.dst, this.rst); rendertree(res, this.ts, this.top, this.dst, this.rst);
} }
@ -5995,7 +5995,7 @@ var treectl = (function () {
thegrid.setvis(true); thegrid.setvis(true);
} }
r.reqls = function (url, hpush, back) { r.reqls = function (url, hpush, back, hydrate) {
if (IE && !history.pushState) if (IE && !history.pushState)
return window.location = url; return window.location = url;
@ -6003,6 +6003,7 @@ var treectl = (function () {
xhr.top = url.split('?')[0]; xhr.top = url.split('?')[0];
xhr.back = back xhr.back = back
xhr.hpush = hpush; xhr.hpush = hpush;
xhr.hydrate = hydrate;
xhr.ts = Date.now(); xhr.ts = Date.now();
xhr.open('GET', xhr.top + '?ls' + (r.dots ? '&dots' : ''), true); xhr.open('GET', xhr.top + '?ls' + (r.dots ? '&dots' : ''), true);
xhr.onload = xhr.onerror = recvls; xhr.onload = xhr.onerror = recvls;
@ -6049,8 +6050,10 @@ var treectl = (function () {
var res = JSON.parse(this.responseText); var res = JSON.parse(this.responseText);
} }
catch (ex) { catch (ex) {
location = this.top; if (!this.hydrate)
return; location = this.top;
return toast.err(30, "bad <code>?ls</code> reply;\nexpected json, got this:\n\n" + esc(this.responseText + ''));
} }
if (r.chk_index_html(this.top, res)) if (r.chk_index_html(this.top, res))
@ -6272,7 +6275,7 @@ var treectl = (function () {
xhr.send(); xhr.send();
r.ls_cb = showfile.addlinks; r.ls_cb = showfile.addlinks;
return r.reqls(get_evpath(), false); return r.reqls(get_evpath(), false, undefined, true);
} }
var top = get_evpath(); var top = get_evpath();

View file

@ -1470,6 +1470,8 @@ var toast = (function () {
}; };
r.show = function (cl, sec, txt, tag) { r.show = function (cl, sec, txt, tag) {
txt = (txt + '').slice(0, 16384);
var same = r.visible && txt == r.p_txt && r.p_sec == sec, var same = r.visible && txt == r.p_txt && r.p_sec == sec,
delta = Date.now() - r.p_t; delta = Date.now() - r.p_t;