diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 89a3490a..03907e5a 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -389,6 +389,8 @@ var Ls = { "md_eshow": "cannot render ", "md_off": "[📜readme] disabled in [⚙️] -- document hidden", + "badreply": "Failed to parse reply from server", + "xhr403": "403: Access denied\n\ntry pressing F5, maybe you got logged out", "cf_ok": "sorry about that -- DD" + wah + "oS protection kicked in\n\nthings should resume in about 30 sec\n\nif nothing happens, hit F5 to reload the page", "tl_xe1": "could not list subfolders:\n\nerror ", @@ -887,6 +889,8 @@ var Ls = { "md_eshow": "viser forenklet ", "md_off": "[📜readme] er avskrudd i [⚙️] -- dokument skjult", + "badreply": "Ugyldig svar ifra serveren", + "xhr403": "403: Tilgang nektet\n\nkanskje du ble logget ut? prøv å trykk F5", "cf_ok": "beklager -- liten tilfeldig kontroll, alt OK\n\nting skal fortsette om ca. 30 sekunder\n\nhvis ikkeno skjer, trykk F5 for å laste siden på nytt", "tl_xe1": "kunne ikke hente undermapper:\n\nfeil ", @@ -969,7 +973,7 @@ var Ls = { "u_emtleakf": 'prøver følgende:\n
🥔
("enkelt UI") i opplasterenconnections-per-server
in about:config
",
+ "u_maxconn": "de fleste nettlesere tillater ikke mer enn 6, men firefox lar deg øke grensen med connections-per-server
i 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", @@ -5554,7 +5558,7 @@ document.onkeydown = function (e) { function xhr_search_results() { if (this.status !== 200) { - var msg = unpre(this.responseText); + var msg = hunpre(this.responseText); srch_msg(true, "http " + this.status + ": " + msg); search_in_progress = 0; return; @@ -7494,7 +7498,7 @@ var msel = (function () { xhrchk(this, L.fd_xe1, L.fd_xe2); if (this.status !== 201) { - sf.textContent = 'error: ' + unpre(this.responseText); + sf.textContent = 'error: ' + hunpre(this.responseText); return; } @@ -7542,7 +7546,7 @@ var msel = (function () { xhrchk(this, L.fsm_xe1, L.fsm_xe2); if (this.status < 200 || this.status > 201) { - sf.textContent = 'error: ' + unpre(this.responseText); + sf.textContent = 'error: ' + hunpre(this.responseText); return; } @@ -7878,7 +7882,12 @@ var unpost = (function () { if (!xhrchk(this, L.fu_xe1, L.fu_xe2)) return ebi('op_unpost').innerHTML = L.fu_xe1; - var res = JSON.parse(this.responseText); + try { + var res = JSON.parse(this.responseText); + } + catch (ex) { + return ebi('op_unpost').innerHTML = '' + L.badreply + ':
' + unpre(this.responseText); + } if (res.length) { if (res.length == 2000) html.push("" + L.un_max); diff --git a/copyparty/web/md2.js b/copyparty/web/md2.js index dc2f702b..e54af570 100644 --- a/copyparty/web/md2.js +++ b/copyparty/web/md2.js @@ -368,14 +368,14 @@ function save(e) { function save_cb() { if (this.status !== 200) - return toast.err(0, 'Error! The file was NOT saved.\n\n' + this.status + ": " + (this.responseText + '').replace(/^
/, "")); + return toast.err(0, 'Error! The file was NOT saved.\n\nError ' + this.status + ":\n" + unpre(this.responseText)); var r; try { r = JSON.parse(this.responseText); } catch (ex) { - return toast.err(0, 'Failed to parse reply from server:\n\n' + this.responseText); + return toast.err(0, 'Error! The file was likely NOT saved.\n\nFailed to parse reply from server:\n\n' + unpre(this.responseText)); } if (!r.ok) { @@ -418,7 +418,7 @@ function run_savechk(lastmod, txt, btn, ntry) { function savechk_cb() { if (this.status !== 200) - return toast.err(0, 'Error! The file was NOT saved.\n\n' + this.status + ": " + (this.responseText + '').replace(/^/, "")); + return toast.err(0, 'Error! The file was NOT saved.\n\nError ' + this.status + ":\n" + unpre(this.responseText)); var doc1 = this.txt.replace(/\r\n/g, "\n"); var doc2 = this.responseText.replace(/\r\n/g, "\n"); diff --git a/copyparty/web/mde.js b/copyparty/web/mde.js index f8de0feb..5c2872df 100644 --- a/copyparty/web/mde.js +++ b/copyparty/web/mde.js @@ -134,14 +134,14 @@ function save(mde) { function save_cb() { if (this.status !== 200) - return toast.err(0, 'Error! The file was NOT saved.\n\n' + this.status + ": " + (this.responseText + '').replace(/^/, "")); + return toast.err(0, 'Error! The file was NOT saved.\n\nError ' + this.status + ":\n" + unpre(this.responseText)); var r; try { r = JSON.parse(this.responseText); } catch (ex) { - return toast.err(0, 'Failed to parse reply from server:\n\n' + this.responseText); + return toast.err(0, 'Error! The file was likely NOT saved.\n\nFailed to parse reply from server:\n\n' + unpre(this.responseText)); } if (!r.ok) { @@ -180,7 +180,7 @@ function save_cb() { function save_chk() { if (this.status !== 200) - return toast.err(0, 'Error! The file was NOT saved.\n\n' + this.status + ": " + (this.responseText + '').replace(/^/, "")); + return toast.err(0, 'Error! The file was NOT saved.\n\nError ' + this.status + ":\n" + unpre(this.responseText)); var doc1 = this.txt.replace(/\r\n/g, "\n"); var doc2 = this.responseText.replace(/\r\n/g, "\n"); diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 5386d5eb..a0c71638 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -2256,6 +2256,7 @@ function up2k_init(subtle) { console.log('handshake onerror, retrying', t.name, t); apop(st.busy.handshake, t); st.todo.handshake.unshift(t); + t.cooldown = Date.now() + 5000 + Math.floor(Math.random() * 3000); t.keepalive = keepalive; }; var orz = function (e) { @@ -2263,16 +2264,26 @@ function up2k_init(subtle) { return console.log('zombie handshake onload', t.name, t); if (xhr.status == 200) { + try { + var response = JSON.parse(xhr.responseText); + } + catch (ex) { + apop(st.busy.handshake, t); + st.todo.handshake.unshift(t); + t.cooldown = Date.now() + 5000 + Math.floor(Math.random() * 3000); + return toast.err(0, 'Handshake error; will retry...\n\n' + L.badreply + ':\n\n' + unpre(xhr.responseText)); + } + t.t_handshake = Date.now(); if (keepalive) { apop(st.busy.handshake, t); + tasker(); return; } if (toast.tag === t) toast.ok(5, L.u_fixed); - var response = JSON.parse(xhr.responseText); if (!response.name) { var msg = '', smsg = ''; diff --git a/copyparty/web/util.js b/copyparty/web/util.js index f654a0a6..c7e5e44f 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1417,9 +1417,12 @@ function lf2br(txt) { } -function unpre(txt) { +function hunpre(txt) { return ('' + txt).replace(/^/, ''); } +function unpre(txt) { + return esc(hunpre(txt)); +} var toast = (function () { @@ -2001,7 +2004,9 @@ function xhrchk(xhr, prefix, e404, lvl, tag) { 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); if (errtxt.startsWith('')) - suf = '\n\nerror-details: «' + errtxt.slice(5).split('\n')[0].trim() + '»'; + suf = '\n\nerror-details: «' + unpre(errtxt).split('\n')[0].trim() + '»'; + else + errtxt = esc(errtxt).slice(0, 32768); if (xhr.status == 403 && !is_cf) return toast.err(0, prefix + (L && L.xhr403 || "403: access denied\n\ntry pressing F5, maybe you got logged out") + suf, tag);