misc optimizations / cleanup:

* slightly faster startup / shutdown
* forgot a jinja2 golf
* waste 4KiB changing prismjs back to gz since brotli is https-gated ;_;
* broke support for firefox<52 (non-var functions must be toplevel
   or immediately within another function), now even firefox 10 /
   centos 6 is somewhat supported again
This commit is contained in:
ed 2023-09-17 13:02:18 +00:00
parent 91cafc2511
commit aa96a1acdc
11 changed files with 131 additions and 93 deletions

View file

@ -328,6 +328,12 @@ upgrade notes
* can I make copyparty download a file to my server if I give it a URL?
* yes, using [hooks](https://github.com/9001/copyparty/blob/hovudstraum/bin/hooks/wget.py)
* i want to learn python and/or programming and am considering looking at the copyparty source code in that occasion
```bash
_| _ __ _ _|_
(_| (_) | | (_) |_
```
# accounts and volumes

View file

@ -69,7 +69,7 @@ class BrokerMp(object):
while procs:
if procs[-1].is_alive():
time.sleep(0.1)
time.sleep(0.05)
continue
procs.pop()

View file

@ -339,7 +339,12 @@ class SvcHub(object):
if self.httpsrv_up != self.broker.num_workers:
return
time.sleep(0.1) # purely cosmetic dw
ar = self.args
for _ in range(10 if ar.ftp or ar.ftps else 0):
time.sleep(0.03)
if self.ftpd:
break
if self.tcpsrv.qr:
self.log("qr-code", self.tcpsrv.qr)
else:
@ -645,19 +650,25 @@ class SvcHub(object):
ret = 1
try:
self.pr("OPYTHAT")
tasks = []
slp = 0.0
if self.mdns:
Daemon(self.mdns.stop)
tasks.append(Daemon(self.mdns.stop, "mdns"))
slp = time.time() + 0.5
if self.ssdp:
Daemon(self.ssdp.stop)
tasks.append(Daemon(self.ssdp.stop, "ssdp"))
slp = time.time() + 0.5
self.broker.shutdown()
self.tcpsrv.shutdown()
self.up2k.shutdown()
if hasattr(self, "smbd"):
slp = max(slp, time.time() + 0.5)
tasks.append(Daemon(self.smbd.stop, "smbd"))
if self.thumbsrv:
self.thumbsrv.shutdown()
@ -667,17 +678,19 @@ class SvcHub(object):
break
if n == 3:
self.pr("waiting for thumbsrv (10sec)...")
self.log("root", "waiting for thumbsrv (10sec)...")
if hasattr(self, "smbd"):
slp = max(slp, time.time() + 0.5)
Daemon(self.kill9, a=(1,))
Daemon(self.smbd.stop)
zf = max(time.time() - slp, 0)
Daemon(self.kill9, a=(zf + 0.5,))
while time.time() < slp:
time.sleep(0.1)
if not next((x for x in tasks if x.is_alive), None):
break
self.pr("nailed it", end="")
time.sleep(0.05)
self.log("root", "nailed it")
ret = self.retcode
except:
self.pr("\033[31m[ error during shutdown ]\n{}\033[0m".format(min_ex()))
@ -687,7 +700,7 @@ class SvcHub(object):
print("\033]0;\033\\", file=sys.stderr, end="")
sys.stderr.flush()
self.pr("\033[0m")
self.pr("\033[0m", end="")
if self.logf:
self.logf.close()

View file

@ -4699,6 +4699,39 @@ function hkhelp() {
var fselgen, fselctr;
function fselfunw(e, ae, d, rem) {
fselctr = 0;
var gen = fselgen = Date.now();
if (rem)
rem *= window.innerHeight;
var selfun = function () {
var el = ae[d + 'ElementSibling'];
if (!el || gen != fselgen)
return;
el.focus();
var elh = el.offsetHeight;
if (ctrl(e))
document.documentElement.scrollTop += (d == 'next' ? 1 : -1) * elh;
if (e.shiftKey) {
clmod(el, 'sel', 't');
msel.origin_tr(el);
msel.selui();
}
rem -= elh;
if (rem > 0) {
ae = document.activeElement;
if (++fselctr % 5 && rem > elh * (FIREFOX ? 5 : 2))
selfun();
else
setTimeout(selfun, 1);
}
}
selfun();
}
document.onkeydown = function (e) {
if (e.altKey || e.isComposing)
return;
@ -4749,37 +4782,7 @@ document.onkeydown = function (e) {
if (k == 'PageUp') { d = 'previous'; rem = 0.6; }
if (k == 'PageDown') { d = 'next'; rem = 0.6; }
if (d) {
fselctr = 0;
var gen = fselgen = Date.now();
if (rem)
rem *= window.innerHeight;
function selfun() {
var el = ae[d + 'ElementSibling'];
if (!el || gen != fselgen)
return;
el.focus();
var elh = el.offsetHeight;
if (ctrl(e))
document.documentElement.scrollTop += (d == 'next' ? 1 : -1) * elh;
if (e.shiftKey) {
clmod(el, 'sel', 't');
msel.origin_tr(el);
msel.selui();
}
rem -= elh;
if (rem > 0) {
ae = document.activeElement;
if (++fselctr % 5 && rem > elh * (FIREFOX ? 5 : 2))
selfun();
else
setTimeout(selfun, 1);
}
}
selfun();
fselfunw(e, ae, d, rem);
return ev(e);
}
if (k == 'Space') {
@ -5268,7 +5271,10 @@ var filecolwidth = (function () {
return;
lastwidth = w;
document.documentElement.style.setProperty('--file-td-w', w + 'em');
try {
document.documentElement.style.setProperty('--file-td-w', w + 'em');
}
catch (ex) { }
}
})();
onresize100.add(filecolwidth, true);
@ -6316,10 +6322,11 @@ var filecols = (function () {
var ths = QSA('#files>thead th>span');
for (var a = 0, aa = ths.length; a < aa; a++) {
var th = ths[a].parentElement,
toh = ths[a].outerHTML, // !ff10
ttv = L.cols[ths[a].textContent];
if (!MOBILE) {
th.innerHTML = '<div class="cfg"><a href="#">-</a></div>' + ths[a].outerHTML;
if (!MOBILE && toh) {
th.innerHTML = '<div class="cfg"><a href="#">-</a></div>' + toh;
th.getElementsByTagName('a')[0].onclick = ev_row_tgl;
}
if (ttv) {
@ -7125,7 +7132,7 @@ function show_md(md, name, div, url, depth) {
wfp_debounce.hide();
if (!marked) {
if (depth)
return toast.warn(10, errmsg + 'failed to load marked.js')
return toast.warn(10, errmsg + (window.WebAssembly ? 'failed to load marked.js' : 'your browser is too old'));
wfp_debounce.n--;
return import_js(SR + '/.cpr/deps/marked.js', function () {

View file

@ -31,7 +31,7 @@
<span id="lno">L#</span>
{%- else %}
<a href="{{ arg_base }}edit" tt="good: higher performance$Ngood: same document width as viewer$Nbad: assumes you know markdown">edit (basic)</a>
<a href="{{ arg_base }}edit2" tt="not in-house so probably less buggy">edit (fancy)</a>
<a href="{{ arg_base }}edit2" id="edit2" tt="not in-house so probably less buggy">edit (fancy)</a>
<a href="{{ arg_base }}">view raw</a>
{%- endif %}
</div>

View file

@ -52,7 +52,7 @@ var img_load = (function () {
var r = {};
r.callbacks = [];
function fire() {
var fire = function () {
for (var a = 0; a < r.callbacks.length; a++)
r.callbacks[a]();
}
@ -472,7 +472,7 @@ img_load.callbacks = [toc.refresh];
// scroll handler
var redraw = (function () {
var sbs = true;
function onresize() {
var onresize = function () {
if (window.matchMedia)
sbs = window.matchMedia('(min-width: 64em)').matches;
@ -485,7 +485,7 @@ var redraw = (function () {
onscroll();
}
function onscroll() {
var onscroll = function () {
toc.refresh();
}
@ -507,6 +507,12 @@ dom_navtgl.onclick = function () {
redraw();
};
if (!HTTPS)
ebi('edit2').onclick = function (e) {
toast.err(0, "the fancy editor is only available over https");
return ev(e);
}
if (sread('hidenav') == 1)
dom_navtgl.onclick();

View file

@ -92,7 +92,7 @@ var action_stack = null;
var nlines = 0;
var draw_md = (function () {
var delay = 1;
function draw_md() {
var draw_md = function () {
var t0 = Date.now();
var src = dom_src.value;
convert_markdown(src, dom_pre);
@ -135,7 +135,7 @@ img_load.callbacks = [function () {
// resize handler
redraw = (function () {
function onresize() {
var onresize = function () {
var y = (dom_hbar.offsetTop + dom_hbar.offsetHeight) + 'px';
dom_wrap.style.top = y;
dom_swrap.style.top = y;
@ -143,12 +143,12 @@ redraw = (function () {
map_src = genmap(dom_ref, map_src);
map_pre = genmap(dom_pre, map_pre);
}
function setsbs() {
var setsbs = function () {
dom_wrap.className = '';
dom_swrap.className = '';
onresize();
}
function modetoggle() {
var modetoggle = function () {
var mode = dom_nsbs.innerHTML;
dom_nsbs.innerHTML = mode == 'editor' ? 'preview' : 'editor';
mode += ' single';
@ -172,7 +172,7 @@ redraw = (function () {
(function () {
var skip_src = false, skip_pre = false;
function scroll(src, srcmap, dst, dstmap) {
var scroll = function (src, srcmap, dst, dstmap) {
var y = src.scrollTop;
if (y < 8) {
dst.scrollTop = 0;
@ -900,12 +900,12 @@ var set_lno = (function () {
pv = null,
lno = ebi('lno');
function poke() {
var poke = function () {
clearTimeout(t);
t = setTimeout(fire, 20);
}
function fire() {
var fire = function () {
try {
clearTimeout(t);
@ -930,7 +930,7 @@ var set_lno = (function () {
// hotkeys / toolbar
(function () {
function keydown(ev) {
var keydown = function (ev) {
ev = ev || window.event;
var kc = ev.code || ev.keyCode || ev.which,
editing = document.activeElement == dom_src;
@ -1058,7 +1058,7 @@ action_stack = (function () {
var ignore = false;
var ref = dom_src.value;
function diff(from, to, cpos) {
var diff = function (from, to, cpos) {
if (from === to)
return null;
@ -1089,14 +1089,14 @@ action_stack = (function () {
};
}
function undiff(from, change) {
var undiff = function (from, change) {
return {
txt: from.substring(0, change.car) + change.txt + from.substring(change.cdr),
cpos: change.cpos
};
}
function apply(src, dst) {
var apply = function (src, dst) {
dbg('undos(%d) redos(%d)', hist.un.length, hist.re.length);
if (src.length === 0)
@ -1120,7 +1120,7 @@ action_stack = (function () {
return true;
}
function schedule_push() {
var schedule_push = function () {
if (ignore) {
ignore = false;
return;
@ -1131,7 +1131,7 @@ action_stack = (function () {
sched_timer = setTimeout(push, 500);
}
function undo() {
var undo = function () {
if (hist.re.length == 0) {
clearTimeout(sched_timer);
push();
@ -1139,11 +1139,11 @@ action_stack = (function () {
return apply(hist.un, hist.re);
}
function redo() {
var redo = function () {
return apply(hist.re, hist.un);
}
function push() {
var push = function () {
var newtxt = dom_src.value;
var change = diff(ref, newtxt, sched_cpos);
if (change !== null)

View file

@ -588,7 +588,7 @@ function U2pvis(act, btns, uc, st) {
btns[a].onclick = function (e) {
ev(e);
var newtab = this.getAttribute('act');
function go() {
var go = function () {
for (var b = 0; b < btns.length; b++) {
btns[b].className = (
btns[b].getAttribute('act') == newtab) ? 'act' : '';
@ -1654,11 +1654,11 @@ function up2k_init(subtle) {
var running = false,
was_busy = false;
function defer() {
var defer = function () {
running = false;
}
function taskerd() {
var taskerd = function () {
if (running)
return;
@ -1956,7 +1956,7 @@ function up2k_init(subtle) {
st.bytes.hashed += cdr - car;
st.etac.h++;
function orz(e) {
var orz = function (e) {
bpend--;
segm_next();
hash_calc(nch, e.target.result);
@ -2239,7 +2239,7 @@ function up2k_init(subtle) {
st.todo.handshake.unshift(t);
t.keepalive = keepalive;
};
function orz(e) {
var orz = function (e) {
if (t.t_busied != me) {
console.log('zombie handshake onload,', t.name, t);
return;
@ -2523,7 +2523,7 @@ function up2k_init(subtle) {
if (cdr >= t.size)
cdr = t.size;
function orz(xhr) {
var orz = function (xhr) {
var txt = ((xhr.response && xhr.response.err) || xhr.responseText) + '';
if (txt.indexOf('upload blocked by x') + 1) {
apop(st.busy.upload, upt);
@ -2552,7 +2552,7 @@ function up2k_init(subtle) {
}
orz2(xhr);
}
function orz2(xhr) {
var orz2 = function (xhr) {
apop(st.busy.upload, upt);
apop(t.postlist, npart);
if (!t.postlist.length) {

View file

@ -140,29 +140,35 @@ catch (ex) {
}
var crashed = false, ignexd = {}, evalex_fatal = false;
function vis_exh(msg, url, lineNo, columnNo, error) {
if ((msg + '').indexOf('ResizeObserver') + 1)
msg = String(msg);
url = String(url);
if (msg.indexOf('ResizeObserver') + 1)
return; // chrome issue 809574 (benign, from <video>)
if ((msg + '').indexOf('l2d.js') + 1)
if (msg.indexOf('l2d.js') + 1)
return; // `t` undefined in tapEvent -> hitTestSimpleCustom
if (!/\.js($|\?)/.exec('' + url))
if (!/\.js($|\?)/.exec(url))
return; // chrome debugger
if ((url + '').indexOf(' > eval') + 1 && !evalex_fatal)
if (url.indexOf(' > eval') + 1 && !evalex_fatal)
return; // md timer
var ekey = url + '\n' + lineNo + '\n' + msg;
if (ignexd[ekey] || crashed)
return;
if (url.indexOf('deps/marked.js') + 1 && !window.WebAssembly)
return; // ff<52
crashed = true;
window.onerror = undefined;
var html = [
'<h1>you hit a bug!</h1>',
'<p style="font-size:1.3em;margin:0;line-height:2em">try to <a href="#" onclick="localStorage.clear();location.reload();">reset copyparty settings</a> if you are stuck here, or <a href="#" onclick="ignex();">ignore this</a> / <a href="#" onclick="ignex(true);">ignore all</a> / <a href="?b=u">basic</a></p>',
'<p style="color:#fff">please send me a screenshot arigathanks gozaimuch: <a href="<ghi>" target="_blank">new github issue</a></p>',
'<p class="b">' + esc(url + ' @' + lineNo + ':' + columnNo), '<br />' + esc(String(msg)).replace(/\n/g, '<br />') + '</p>',
'<p class="b">' + esc(url + ' @' + lineNo + ':' + columnNo), '<br />' + esc(msg).replace(/\n/g, '<br />') + '</p>',
'<p><b>UA:</b> ' + esc(navigator.userAgent + '')
];
@ -354,13 +360,13 @@ catch (ex) {
}
// https://stackoverflow.com/a/950146
function import_js(url, cb) {
function import_js(url, cb, ecb) {
var head = document.head || document.getElementsByTagName('head')[0];
var script = mknod('script');
script.type = 'text/javascript';
script.src = url;
script.onload = cb;
script.onerror = function () {
script.onerror = ecb || function () {
var m = 'Failed to load module:\n' + url;
console.log(m);
toast.err(0, m);
@ -1141,7 +1147,7 @@ var timer = (function () {
apop(r.q, fun);
};
function doevents() {
var doevents = function () {
if (crashed)
return;
@ -1352,7 +1358,7 @@ var toast = (function () {
r.p_sec = 0;
r.p_t = 0;
function scrollchk() {
var scrollchk = function () {
if (scrolling)
return;
@ -1367,7 +1373,7 @@ var toast = (function () {
scrolling = true;
}
function unscroll() {
var unscroll = function () {
timer.rm(scrollchk);
clmod(obj, 'scroll');
scrolling = false;
@ -1486,7 +1492,7 @@ var modal = (function () {
r.busy = false;
setTimeout(next, 50);
};
function ok(e) {
var ok = function (e) {
ev(e);
var v = ebi('modali');
v = v ? v.value : true;
@ -1494,14 +1500,14 @@ var modal = (function () {
if (cb_ok)
cb_ok(v);
}
function ng(e) {
var ng = function (e) {
ev(e);
r.hide();
if (cb_ng)
cb_ng(null);
}
function onfocus(e) {
var onfocus = function (e) {
var ctr = ebi('modalc');
if (!ctr || !ctr.contains || !document.activeElement || ctr.contains(document.activeElement))
return;
@ -1513,7 +1519,7 @@ var modal = (function () {
ev(e);
}
function onkey(e) {
var onkey = function (e) {
var k = e.code,
eok = ebi('modal-ok'),
eng = ebi('modal-ng'),
@ -1536,7 +1542,7 @@ var modal = (function () {
return ng();
}
function next() {
var next = function () {
if (!r.busy && q.length)
q.shift()();
}
@ -1547,7 +1553,7 @@ var modal = (function () {
});
next();
};
function _alert(html, cb, fun) {
var _alert = function (html, cb, fun) {
cb_ok = cb_ng = cb;
cb_up = fun;
html += '<div id="modalb"><a href="#" id="modal-ok">OK</a></div>';
@ -1560,7 +1566,7 @@ var modal = (function () {
});
next();
}
function _confirm(html, cok, cng, fun, btns) {
var _confirm = function (html, cok, cng, fun, btns) {
cb_ok = cok;
cb_ng = cng === undefined ? cok : cng;
cb_up = fun;
@ -1574,7 +1580,7 @@ var modal = (function () {
});
next();
}
function _prompt(html, v, cok, cng, fun) {
var _prompt = function (html, v, cok, cng, fun) {
cb_ok = cok;
cb_ng = cng === undefined ? cok : null;
cb_up = fun;
@ -1793,7 +1799,7 @@ var favico = (function () {
r.en = true;
r.tag = null;
function gx(txt) {
var gx = function (txt) {
return (svg_decl +
'<svg version="1.1" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">\n' +
(r.bg ? '<rect width="100%" height="100%" rx="16" fill="#' + r.bg + '" />\n' : '') +

View file

@ -1,4 +1,4 @@
all: $(addsuffix .br, $(wildcard prism* easymde*))
all: $(addsuffix .br, $(wildcard easymde*))
%.br: %
brotli -jZ $<

View file

@ -481,7 +481,7 @@ iawk '/^[^ ]/{s=0}/^def babel_extract/{s=1}!s' j2/jinja2/ext.py
ised '/InternationalizationExtension/d' j2/jinja2/ext.py
iawk '/^class/{s=0}/^class (Package|Dict|Function|Prefix|Choice|Module)Loader/{s=1}!s' j2/jinja2/loaders.py
sed -ri '/^from .bccache | (Package|Dict|Function|Prefix|Choice|Module)Loader$/d' j2/jinja2/__init__.py
rm -f j2/jinja2/async* j2/jinja2/bccache.py
rm -f j2/jinja2/async* j2/jinja2/{bccache,sandbox}.py
cat > j2/jinja2/_identifier.py <<'EOF'
import re
pattern = re.compile(r"\w+")