mirror of
				https://github.com/9001/copyparty.git
				synced 2025-11-03 21:43:12 +00:00 
			
		
		
		
	add pane with total eta for all uploads
This commit is contained in:
		@@ -530,24 +530,9 @@ html.light #wfm a:not(.en) {
 | 
			
		||||
	box-shadow: 0 -.15em .2em #000 inset;
 | 
			
		||||
	padding-bottom: .3em;
 | 
			
		||||
}
 | 
			
		||||
#ops i {
 | 
			
		||||
	font-size: 1.5em;
 | 
			
		||||
}
 | 
			
		||||
#ops i:before {
 | 
			
		||||
	content: 'x';
 | 
			
		||||
	color: #282828;
 | 
			
		||||
	text-shadow: 0 0 .08em #01a7e1;
 | 
			
		||||
	position: relative;
 | 
			
		||||
}
 | 
			
		||||
#ops i:after {
 | 
			
		||||
	content: 'x';
 | 
			
		||||
	color: #282828;
 | 
			
		||||
	text-shadow: 0 0 .08em #ff3f1a;
 | 
			
		||||
	margin-left: -.35em;
 | 
			
		||||
	font-size: 1.05em;
 | 
			
		||||
}
 | 
			
		||||
#ops,
 | 
			
		||||
.opbox {
 | 
			
		||||
.opbox,
 | 
			
		||||
#u2etas {
 | 
			
		||||
	border: 1px solid #3a3a3a;
 | 
			
		||||
	box-shadow: 0 0 1em #222 inset;
 | 
			
		||||
}
 | 
			
		||||
@@ -1060,7 +1045,8 @@ html.light {
 | 
			
		||||
}
 | 
			
		||||
html.light #ops,
 | 
			
		||||
html.light .opbox,
 | 
			
		||||
html.light #srch_form {
 | 
			
		||||
html.light #srch_form,
 | 
			
		||||
html.light #u2etas {
 | 
			
		||||
	background: #f7f7f7;
 | 
			
		||||
	box-shadow: 0 0 .3em #ddd;
 | 
			
		||||
	border-color: #f7f7f7;
 | 
			
		||||
@@ -1564,7 +1550,7 @@ html.light #bbox-overlay figcaption a {
 | 
			
		||||
	color: #333;
 | 
			
		||||
}
 | 
			
		||||
#u2conf #u2btn {
 | 
			
		||||
	margin: -1.5em 0;
 | 
			
		||||
	margin: -2.4em 0;
 | 
			
		||||
	padding: .8em 0;
 | 
			
		||||
	width: 100%;
 | 
			
		||||
	max-width: 12em;
 | 
			
		||||
@@ -1611,17 +1597,38 @@ html.light #bbox-overlay figcaption a {
 | 
			
		||||
#u2tab tbody tr:hover td {
 | 
			
		||||
	background: #222;
 | 
			
		||||
}
 | 
			
		||||
#u2etas {
 | 
			
		||||
	background: #333;
 | 
			
		||||
	padding: .2em .5em;
 | 
			
		||||
	border-radius: .5em;
 | 
			
		||||
	border-width: .25em 0;
 | 
			
		||||
	width: 20em;
 | 
			
		||||
	text-align: left;
 | 
			
		||||
	white-space: nowrap;
 | 
			
		||||
	display: inline-block;
 | 
			
		||||
	font-family: 'scp', monospace, monospace;
 | 
			
		||||
}
 | 
			
		||||
#u2etaw {
 | 
			
		||||
	width: 21em;
 | 
			
		||||
	font-size: .94em;
 | 
			
		||||
	margin: 2.5em auto 1em auto;
 | 
			
		||||
}
 | 
			
		||||
#u2cards {
 | 
			
		||||
	padding: 1em 0 .3em 1em;
 | 
			
		||||
	margin: 1.5em auto -2.5em auto;
 | 
			
		||||
	padding: 1em 1em .3em 1em;
 | 
			
		||||
	margin: 0 auto -1.5em auto;
 | 
			
		||||
	white-space: nowrap;
 | 
			
		||||
	text-align: center;
 | 
			
		||||
	overflow: hidden;
 | 
			
		||||
}
 | 
			
		||||
#u2cards.w {
 | 
			
		||||
	width: 45em;
 | 
			
		||||
	width: 44em;
 | 
			
		||||
	text-align: left;
 | 
			
		||||
}
 | 
			
		||||
#u2etaw.w {
 | 
			
		||||
	width: 52em;
 | 
			
		||||
	text-align: right;
 | 
			
		||||
	margin: 3em auto -3em auto;
 | 
			
		||||
}
 | 
			
		||||
#u2cards a {
 | 
			
		||||
	padding: .2em 1em;
 | 
			
		||||
	border: 1px solid #777;
 | 
			
		||||
 
 | 
			
		||||
@@ -102,6 +102,11 @@ ebi('op_up2k').innerHTML = (
 | 
			
		||||
	'	</div>\n' +
 | 
			
		||||
	'</div>\n' +
 | 
			
		||||
 | 
			
		||||
	'<div id="u2etaw"><div id="u2etas">\n' +
 | 
			
		||||
	'	hash: <span id="u2etah" tt="average <em>hashing</em> speed, and estimated time until finish">(nothing to do yet)</span><br />\n' +
 | 
			
		||||
	'	send: <span id="u2etau" tt="average <em>upload</em> speed and estimated time until finish">(nothing to do yet)</span>\n' +
 | 
			
		||||
	'</div></div>\n' +
 | 
			
		||||
 | 
			
		||||
	'<div id="u2cards">\n' +
 | 
			
		||||
	'	<a href="#" act="ok" tt="completed successfully">ok <span>0</span></a><a\n' +
 | 
			
		||||
	'	href="#" act="ng" tt="failed / rejected / not-found">ng <span>0</span></a><a\n' +
 | 
			
		||||
 
 | 
			
		||||
@@ -596,8 +596,14 @@ function up2k_init(subtle) {
 | 
			
		||||
            "upload": []
 | 
			
		||||
        },
 | 
			
		||||
        "bytes": {
 | 
			
		||||
            "total": 0,
 | 
			
		||||
            "hashed": 0,
 | 
			
		||||
            "uploaded": 0
 | 
			
		||||
            "uploaded": 0,
 | 
			
		||||
            "finished": 0
 | 
			
		||||
        },
 | 
			
		||||
        "time": {
 | 
			
		||||
            "hashing": 0,
 | 
			
		||||
            "uploading": 0
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@@ -849,6 +855,7 @@ function up2k_init(subtle) {
 | 
			
		||||
                ''
 | 
			
		||||
            ], fobj.size, draw_each);
 | 
			
		||||
 | 
			
		||||
            st.bytes.total += fobj.size;
 | 
			
		||||
            st.files.push(entry);
 | 
			
		||||
            if (turbo)
 | 
			
		||||
                push_t(st.todo.head, entry);
 | 
			
		||||
@@ -887,6 +894,54 @@ function up2k_init(subtle) {
 | 
			
		||||
    }
 | 
			
		||||
    ebi('u2cleanup').onclick = u2cleanup;
 | 
			
		||||
 | 
			
		||||
    var etaref = 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,
 | 
			
		||||
            now = Date.now(),
 | 
			
		||||
            td = (now - (etaref || now)) / 1000.0;
 | 
			
		||||
 | 
			
		||||
        etaref = now;
 | 
			
		||||
 | 
			
		||||
        if (!nhash)
 | 
			
		||||
            ebi('u2etah').innerHTML = 'Done ({0}, {1} files)'.format(humansize(st.bytes.hashed), pvis.ctr["ok"] + pvis.ctr["ng"]);
 | 
			
		||||
 | 
			
		||||
        if (!nsend && !nhash)
 | 
			
		||||
            ebi('u2etau').innerHTML = 'Done ({0}, {1} files)'.format(humansize(st.bytes.uploaded), pvis.ctr["ok"] + pvis.ctr["ng"]);
 | 
			
		||||
 | 
			
		||||
        if (!parallel_uploads || !(nhash + nsend))
 | 
			
		||||
            return;
 | 
			
		||||
 | 
			
		||||
        var t = [];
 | 
			
		||||
        if (nhash && (st.busy.hash.length || hashing_permitted())) {
 | 
			
		||||
            st.time.hashing += td;
 | 
			
		||||
            t.push(['u2etah', st.bytes.hashed, st.time.hashing]);
 | 
			
		||||
        }
 | 
			
		||||
        if (nsend) {
 | 
			
		||||
            st.time.uploading += td;
 | 
			
		||||
            t.push(['u2etau', st.bytes.uploaded, st.time.uploading]);
 | 
			
		||||
        }
 | 
			
		||||
        for (var a = 0; a < t.length; a++) {
 | 
			
		||||
            var rem = st.bytes.total - t[a][1],
 | 
			
		||||
                bps = t[a][1] / t[a][2],
 | 
			
		||||
                eta = Math.floor(rem / bps);
 | 
			
		||||
 | 
			
		||||
            if (t[a][1] < 1024 || t[a][2] < 0.1) {
 | 
			
		||||
                ebi(t[a][0]).innerHTML = '(nothing to do yet)';
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (eta < 60 * 60 * 24)
 | 
			
		||||
                try {
 | 
			
		||||
                    eta = /.*(..:..:..).*/.exec(new Date(eta * 1000).toUTCString())[1];
 | 
			
		||||
                }
 | 
			
		||||
                catch (ex) { }
 | 
			
		||||
 | 
			
		||||
            ebi(t[a][0]).innerHTML = '{0}, {1}/s, {2}'.format(
 | 
			
		||||
                humansize(rem), humansize(bps, 1), eta);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /////
 | 
			
		||||
    ////
 | 
			
		||||
    ///   actuator
 | 
			
		||||
@@ -926,7 +981,7 @@ function up2k_init(subtle) {
 | 
			
		||||
 | 
			
		||||
    function hashing_permitted() {
 | 
			
		||||
        if (multitask) {
 | 
			
		||||
            var ahead = st.bytes.hashed - st.bytes.uploaded;
 | 
			
		||||
            var ahead = st.bytes.hashed - st.bytes.finished;
 | 
			
		||||
            return ahead < 1024 * 1024 * 1024 * 4 &&
 | 
			
		||||
                st.todo.handshake.length + st.busy.handshake.length < 16;
 | 
			
		||||
        }
 | 
			
		||||
@@ -990,7 +1045,12 @@ function up2k_init(subtle) {
 | 
			
		||||
                            toast.err(t, 'All {1} {0} {2}'.format(k, ng, tng));
 | 
			
		||||
                        else if (ng)
 | 
			
		||||
                            toast.err(t, '{0} {1}'.format(ks, tng));
 | 
			
		||||
 | 
			
		||||
                        etafun();
 | 
			
		||||
                        timer.rm(etafun);
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                        timer.add(etafun);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (flag) {
 | 
			
		||||
@@ -1131,7 +1191,6 @@ function up2k_init(subtle) {
 | 
			
		||||
    function exec_hash() {
 | 
			
		||||
        var t = st.todo.hash.shift();
 | 
			
		||||
        st.busy.hash.push(t);
 | 
			
		||||
        st.bytes.hashed += t.size;
 | 
			
		||||
        t.bytes_uploaded = 0;
 | 
			
		||||
 | 
			
		||||
        var bpend = 0,
 | 
			
		||||
@@ -1157,6 +1216,7 @@ function up2k_init(subtle) {
 | 
			
		||||
                cdr = t.size;
 | 
			
		||||
 | 
			
		||||
            bpend += cdr - car;
 | 
			
		||||
            st.bytes.hashed += cdr - car;
 | 
			
		||||
 | 
			
		||||
            function orz(e) {
 | 
			
		||||
                if (!min_filebuf && nch == 1) {
 | 
			
		||||
@@ -1187,7 +1247,7 @@ function up2k_init(subtle) {
 | 
			
		||||
                if (handled) {
 | 
			
		||||
                    pvis.move(t.n, 'ng');
 | 
			
		||||
                    apop(st.busy.hash, t);
 | 
			
		||||
                    st.bytes.uploaded += t.size;
 | 
			
		||||
                    st.bytes.finished += t.size;
 | 
			
		||||
                    return tasker();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@@ -1284,7 +1344,7 @@ function up2k_init(subtle) {
 | 
			
		||||
 | 
			
		||||
            t.done = true;
 | 
			
		||||
            st.bytes.hashed += t.size;
 | 
			
		||||
            st.bytes.uploaded += t.size;
 | 
			
		||||
            st.bytes.finished += t.size;
 | 
			
		||||
            pvis.seth(t.n, 1, 'YOLO');
 | 
			
		||||
            pvis.seth(t.n, 2, "turbo'd");
 | 
			
		||||
            pvis.move(t.n, 'ok');
 | 
			
		||||
@@ -1364,7 +1424,7 @@ function up2k_init(subtle) {
 | 
			
		||||
                    pvis.seth(t.n, 1, smsg);
 | 
			
		||||
                    pvis.move(t.n, smsg == '404' ? 'ng' : 'ok');
 | 
			
		||||
                    apop(st.busy.handshake, t);
 | 
			
		||||
                    st.bytes.uploaded += t.size;
 | 
			
		||||
                    st.bytes.finished += t.size;
 | 
			
		||||
                    t.done = true;
 | 
			
		||||
                    tasker();
 | 
			
		||||
                    return;
 | 
			
		||||
@@ -1432,12 +1492,12 @@ function up2k_init(subtle) {
 | 
			
		||||
 | 
			
		||||
                if (done) {
 | 
			
		||||
                    t.done = true;
 | 
			
		||||
                    st.bytes.uploaded += t.size - t.bytes_uploaded;
 | 
			
		||||
                    var spd1 = (t.size / ((t.t_hashed - t.t_hashing) / 1000.)) / (1024 * 1024.),
 | 
			
		||||
                        spd2 = (t.size / ((t.t_uploaded - t.t_uploading) / 1000.)) / (1024 * 1024.);
 | 
			
		||||
                    st.bytes.finished += t.size - t.bytes_uploaded;
 | 
			
		||||
                    var spd1 = t.size / ((t.t_hashed - t.t_hashing) / 1000.),
 | 
			
		||||
                        spd2 = t.size / ((t.t_uploaded - t.t_uploading) / 1000.);
 | 
			
		||||
 | 
			
		||||
                    pvis.seth(t.n, 2, 'hash {0}, up {1} MB/s'.format(
 | 
			
		||||
                        spd1.toFixed(2), spd2.toFixed(2)));
 | 
			
		||||
                    pvis.seth(t.n, 2, 'hash {0}/s, up {1}/s'.format(
 | 
			
		||||
                        humansize(spd1), isNaN(spd2) ? '--' : humansize(spd2)));
 | 
			
		||||
 | 
			
		||||
                    pvis.move(t.n, 'ok');
 | 
			
		||||
                }
 | 
			
		||||
@@ -1465,7 +1525,7 @@ function up2k_init(subtle) {
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                st.bytes.uploaded += t.size;
 | 
			
		||||
                st.bytes.finished += t.size;
 | 
			
		||||
                if (rsp.indexOf('partial upload exists') !== -1 ||
 | 
			
		||||
                    rsp.indexOf('file already exists') !== -1) {
 | 
			
		||||
                    err = rsp;
 | 
			
		||||
@@ -1536,6 +1596,7 @@ function up2k_init(subtle) {
 | 
			
		||||
            var txt = ((xhr.response && xhr.response.err) || xhr.responseText) + '';
 | 
			
		||||
            if (xhr.status == 200) {
 | 
			
		||||
                pvis.prog(t, npart, cdr - car);
 | 
			
		||||
                st.bytes.finished += cdr - car;
 | 
			
		||||
                st.bytes.uploaded += cdr - car;
 | 
			
		||||
                t.bytes_uploaded += cdr - car;
 | 
			
		||||
            }
 | 
			
		||||
@@ -1603,6 +1664,7 @@ function up2k_init(subtle) {
 | 
			
		||||
            parent.appendChild(btn);
 | 
			
		||||
            ebi('u2conf').setAttribute('class', wide ? 'has_btn' : '');
 | 
			
		||||
            ebi('u2cards').setAttribute('class', wide ? 'w' : '');
 | 
			
		||||
            ebi('u2etaw').setAttribute('class', wide ? 'w' : '');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    window.addEventListener('resize', onresize);
 | 
			
		||||
 
 | 
			
		||||
@@ -401,6 +401,19 @@ function s2ms(s) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function humansize(b, terse) {
 | 
			
		||||
	var i=0, u=terse? ['B','K','M','G'] : ['B','KB','MB','GB'];
 | 
			
		||||
	while (b >= 1000 && i<u.length) {
 | 
			
		||||
		b /= 1024;
 | 
			
		||||
		i += 1;
 | 
			
		||||
	}
 | 
			
		||||
	u = ' ' + u[i];
 | 
			
		||||
	if (b>=100) return Math.floor(b) + u;
 | 
			
		||||
	if (b>=10) return b.toFixed(1) + u;
 | 
			
		||||
	return b.toFixed(2) + u;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function has(haystack, needle) {
 | 
			
		||||
    for (var a = 0; a < haystack.length; a++)
 | 
			
		||||
        if (haystack[a] == needle)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user