autopotato

This commit is contained in:
ed 2022-07-15 02:39:32 +02:00
parent 21bbdb5419
commit c2a0b1b4c6
7 changed files with 120 additions and 28 deletions

View file

@ -18,7 +18,7 @@ var u2min = `
<style>
#ops, #path, #tree, #files, #epi+div+h2,
#u2conf td.c+.c, #u2cards, #u2foot, #srch_dz, #srch_zd {
#u2conf td.c+.c, #u2cards, #srch_dz, #srch_zd {
display: none !important;
}
#u2conf {margin:5em auto 0 auto !important}

View file

@ -358,6 +358,9 @@ class SvcHub(object):
print("nailed it", end="")
ret = self.retcode
except:
print("\033[31m[ error during shutdown ]\n{}\033[0m".format(min_ex()))
raise
finally:
if self.args.wintitle:
print("\033]0;\033\\", file=sys.stderr, end="")

View file

@ -2515,6 +2515,9 @@ class Up2k(object):
except:
pass
if self.args.nw:
return
path = os.path.join(histpath, "up2k.snap")
if not reg:
if ptop not in self.snap_prev or self.snap_prev[ptop] is not None:

View file

@ -2454,11 +2454,11 @@ html.b #u2conf a.b:hover {
color: var(--fg-max);
font-style: italic;
text-align: center;
font-size: .9em;
margin: 1em 0;
font-size: 1.2em;
margin: .8em 0;
}
#u2foot .warn {
font-size: 1.3em;
font-size: 1.2em;
padding: .5em .8em;
margin: 1em -.6em;
border-width: .1em 0;
@ -2472,6 +2472,9 @@ html.b #u2conf a.b:hover {
font-size: .9em;
font-weight: normal;
}
#u2foot>*+* {
margin-top: 1.5em;
}
.prog {
font-family: 'scp', monospace, monospace;
}

View file

@ -288,6 +288,9 @@ var Ls = {
"u_https2": "switch to https",
"u_https3": "for much better performance",
"u_ancient": 'your browser is impressively ancient -- maybe you should <a href="#" onclick="goto(\'bup\')">use bup instead</a>',
"u_enpot": 'switch to <a href="#">potato UI</a> (may improve upload speed)',
"u_depot": 'switch to <a href="#">fancy UI</a> (may reduce upload speed)',
"u_gotpot": 'switching to the potato UI for improved upload speed,\n\nfeel free to disagree and switch back!',
"u_ever": "this is the basic uploader; up2k needs at least<br>chrome 21 // firefox 13 // edge 12 // opera 12 // safari 5.1",
"u_su2k": 'this is the basic uploader; <a href="#" id="u2yea">up2k</a> is better',
"u_ewrite": 'you do not have write-access to this folder',
@ -616,6 +619,9 @@ var Ls = {
"u_https2": "bytte til https",
"u_https3": "for mye høyere hastighet",
"u_ancient": 'nettleseren din er prehistorisk -- mulig du burde <a href="#" onclick="goto(\'bup\')">bruke bup istedenfor</a>',
"u_enpot": 'bytt til <a href="#">enkelt UI</a> (gir sannsynlig raskere opplastning)',
"u_depot": 'bytt til <a href="#">snæsent UI</a> (gir sannsynlig tregere opplastning)',
"u_gotpot": 'byttet til et enklere UI for å laste opp raskere,\n\ndu kan gjerne bytte tilbake altså!',
"u_ever": "dette er den primitive opplasteren; up2k krever minst:<br>chrome 21 // firefox 13 // edge 12 // opera 12 // safari 5.1",
"u_su2k": 'dette er den primitive opplasteren; <a href="#" id="u2yea">up2k</a> er bedre',
"u_ewrite": 'du har ikke skrivetilgang i denne mappen',
@ -785,7 +791,7 @@ ebi('op_up2k').innerHTML = (
'</table><div id="u2mu"></div></div>\n' +
'<p id="u2flagblock"><b>' + L.ul_flagblk + '</p>\n' +
'<p id="u2foot"></p>'
'<div id="u2foot"></div>'
);

View file

@ -136,7 +136,7 @@ function up2k_flagbus() {
}
function U2pvis(act, btns, uc) {
function U2pvis(act, btns, uc, st) {
var r = this;
r.act = act;
r.ctr = { "ok": 0, "ng": 0, "bz": 0, "q": 0 };
@ -145,6 +145,8 @@ function U2pvis(act, btns, uc) {
r.tail = -1;
r.wsz = 3;
r.npotato = 99;
r.modn = 0;
r.modv = 0;
var markup = {
'404': '<span class="err">404</span>',
@ -347,7 +349,10 @@ function U2pvis(act, btns, uc) {
};
r.bzw = function () {
var first = QS('#u2tab>tbody>tr:first-child');
var mod = 0,
t0 = Date.now(),
first = QS('#u2tab>tbody>tr:first-child');
if (!first)
return;
@ -357,17 +362,67 @@ function U2pvis(act, btns, uc) {
while (r.head - first > r.wsz) {
qsr('#f' + (first++));
mod++;
}
while (last - r.tail < r.wsz && last < r.tab.length - 2) {
while (last - r.tail < r.wsz && last < r.tab.length - 1) {
var obj = ebi('f' + (++last));
if (!obj)
if (!obj) {
r.addrow(last);
mod++;
}
}
if (mod && r.modn < 200 && ebi('repl').offsetTop) {
if (++r.modn >= 10)
r.modv += Date.now() - t0;
if (r.modn >= 200) {
var d = r.modv / (r.modn - 10);
console.log('bzw:', d, ', tab:' + r.tab.length);
if (d >= 1.5 && r.tab.length >= 1000 && st.bytes.total / r.tab.length < 1024 * 1024 * 4)
r.go_potato();
}
}
};
r.potatolabels = function () {
var ode = ebi('u2depotato'),
oen = ebi('u2enpotato');
if (!ode)
return;
ode.style.display = uc.potato ? '' : 'none';
oen.style.display = uc.potato ? 'none' : '';
}
r.potato = function () {
ebi('u2tabw').style.minHeight = '';
QS('#u2cards a[act="bz"]').click();
timer[uc.potato ? "add" : "rm"](draw_potato);
r.potatolabels();
};
r.go_potato = function () {
r.go_potato = noop;
var ode = mknod('div', 'u2depotato'),
oen = mknod('div', 'u2enpotato'),
u2f = ebi('u2foot'),
btn = ebi('potato');
ode.innerHTML = L.u_depot;
oen.innerHTML = L.u_enpot;
if (sread('potato') === null) {
btn.click();
toast.inf(30, L.u_gotpot);
localStorage.removeItem('potato');
}
u2f.appendChild(ode);
u2f.appendChild(oen);
ode.onclick = oen.onclick = btn.onclick;
r.potatolabels();
};
function draw_potato() {
@ -582,7 +637,7 @@ function Donut(uc, st) {
v = pos() - r.base,
ofs = o - o * v / t;
if (!uc.potato || ++r.dc >= 2) {
if (!uc.potato || ++r.dc >= 4) {
el.style.strokeDashoffset = ofs;
r.dc = 0;
}
@ -661,7 +716,10 @@ function up2k_init(subtle) {
m = L.u_ancient;
setmsg('');
}
ebi('u2foot').innerHTML = '<big>' + m + '</big>';
qsr('#u2depmsg');
var o = mknod('div', 'u2depmsg');
o.innerHTML = m;
ebi('u2foot').appendChild(o);
}
loading_deps = true;
}
@ -737,7 +795,9 @@ function up2k_init(subtle) {
"hashing": 0,
"uploading": 0,
"busy": 0
}
},
"modv": 0,
"modn": 0
};
function push_t(arr, t) {
@ -749,7 +809,7 @@ function up2k_init(subtle) {
});
}
var pvis = new U2pvis("bz", '#u2cards', uc),
var pvis = new U2pvis("bz", '#u2cards', uc, st),
donut = new Donut(uc, st);
r.ui = pvis;
@ -1148,7 +1208,7 @@ function up2k_init(subtle) {
}
more_one_file();
var etaref = 0, etaskip = 0, utw_minh = 0;
var etaref = 0, etaskip = 0, utw_minh = 0, utw_read = 0;
function etafun() {
var nhash = st.busy.head.length + st.busy.hash.length + st.todo.head.length + st.todo.hash.length,
nsend = st.busy.upload.length + st.todo.upload.length,
@ -1161,6 +1221,11 @@ function up2k_init(subtle) {
//ebi('acc_info').innerHTML = humantime(st.time.busy) + ' ' + f2f(now / 1000, 1);
if (++utw_read >= 20) {
utw_read = 0;
utw_minh = parseInt(ebi('u2tabw').style.minHeight || '0');
}
var minh = QS('#op_up2k.act') && st.is_busy ? Math.max(utw_minh, ebi('u2tab').offsetHeight + 32) : 0;
if (utw_minh < minh || !utw_minh) {
utw_minh = minh;
@ -1425,6 +1490,20 @@ function up2k_init(subtle) {
mou_ikkai = true;
}
if (is_busy && st.modn < 100) {
var t0 = Date.now() + (ebi('repl').offsetTop ? 0 : 0);
if (++st.modn >= 10)
st.modv += Date.now() - t0;
if (st.modn >= 100) {
var d = st.modv / (st.modn - 10);
console.log('tsk:', d);
if (d >= 1.2)
pvis.go_potato();
}
}
if (!mou_ikkai || crashed)
return defer();
}
@ -2103,21 +2182,19 @@ function up2k_init(subtle) {
}
function draw_turbo() {
var msg = uc.fsearch ? L.u_ts : L.u_tu,
omsg = uc.fsearch ? L.u_tu : L.u_ts,
html = ebi('u2foot').innerHTML,
ohtml = html;
var msg = (turbolvl || !uc.turbo) ? null : uc.fsearch ? L.u_ts : L.u_tu,
html = ebi('u2foot').innerHTML;
if (turbolvl || !uc.turbo)
msg = null;
if (msg && html.indexOf(msg) + 1)
return;
if (msg && html.indexOf(msg) === -1)
html = html.replace(omsg, '') + msg;
else if (!msg)
html = html.replace(L.u_tu, '').replace(L.u_ts, '');
qsr('#u2turbomsg');
if (!msg)
return;
if (html !== ohtml)
ebi('u2foot').innerHTML = html;
var o = mknod('div', 'u2turbomsg');
o.innerHTML = msg;
ebi('u2foot').appendChild(o);
}
draw_turbo();

View file

@ -48,10 +48,10 @@ avg() { awk 'function pr(ncsz) {if (nsmp>0) {printf "%3s %s\n", csz, sum/nsmp} c
## time between first and last upload
python3 -um copyparty -nw -v srv::rw -i 127.0.0.1 2>&1 | tee log
cat log | awk '!/"purl"/{next} {s=$1;sub(/[^m]+m/,"");gsub(/:/," ");t=60*(60*$1+$2)+$3} !a{a=t;sa=s} {b=t;sb=s} END {print b-a,sa,sb}'
cat log | awk '!/"purl"/{next} {s=$1;sub(/[^m]+m/,"");gsub(/:/," ");t=60*(60*$1+$2)+$3} t<p{t+=86400} !a{a=t;sa=s} {b=t;sb=s} END {print b-a,sa,sb}'
# or if the client youre measuring dies for ~15sec every once ina while and you wanna filter those out,
cat log | awk '!/"purl"/{next} {s=$1;sub(/[^m]+m/,"");gsub(/:/," ");t=60*(60*$1+$2)+$3} !p{a=t;p=t;r=0;next} t-p>1{printf "%.3f += %.3f - %.3f (%.3f) # %.3f -> %.3f\n",r,p,a,p-a,p,t;r+=p-a;a=t} {p=t} END {print r+p-a}'
cat log | awk '!/"purl"/{next} {s=$1;sub(/[^m]+m/,"");gsub(/:/," ");t=60*(60*$1+$2)+$3} t<p{t+=86400} !p{a=t;p=t;r=0;next} t-p>1{printf "%.3f += %.3f - %.3f (%.3f) # %.3f -> %.3f\n",r,p,a,p-a,p,t;r+=p-a;a=t} {p=t} END {print r+p-a}'
##