mirror of
https://github.com/9001/copyparty.git
synced 2025-08-21 02:42:21 -06:00
fix up2k progressbars
This commit is contained in:
parent
f8c11faada
commit
0546210687
|
@ -141,7 +141,7 @@ function U2pvis(act, btns) {
|
||||||
this.tail = -1;
|
this.tail = -1;
|
||||||
this.wsz = 3;
|
this.wsz = 3;
|
||||||
|
|
||||||
this.addfile = function (entry) {
|
this.addfile = function (entry, sz) {
|
||||||
this.tab.push({
|
this.tab.push({
|
||||||
"hn": entry[0],
|
"hn": entry[0],
|
||||||
"ht": entry[1],
|
"ht": entry[1],
|
||||||
|
@ -149,8 +149,10 @@ function U2pvis(act, btns) {
|
||||||
"in": 'q',
|
"in": 'q',
|
||||||
"nh": 0, //hashed
|
"nh": 0, //hashed
|
||||||
"nd": 0, //done
|
"nd": 0, //done
|
||||||
"pa": [], //percents
|
"cb": [], // bytes done in chunk
|
||||||
"pb": [] //active-list
|
"bt": sz, // bytes total
|
||||||
|
"bd": 0, // bytes done
|
||||||
|
"bd0": 0 // upload start
|
||||||
});
|
});
|
||||||
this.ctr["q"]++;
|
this.ctr["q"]++;
|
||||||
this.drawcard("q");
|
this.drawcard("q");
|
||||||
|
@ -184,28 +186,39 @@ function U2pvis(act, btns) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setab = function (nfile, blocks) {
|
this.setab = function (nfile, nblocks) {
|
||||||
var t = [];
|
var t = [];
|
||||||
for (var a = 0; a < blocks; a++)
|
for (var a = 0; a < nblocks; a++)
|
||||||
t.push(0);
|
t.push(0);
|
||||||
|
|
||||||
this.tab[nfile].pa = t;
|
this.tab[nfile].cb = t;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.perc = function (n, t, e, sz, t0) {
|
this.setat = function (nfile, blocktab) {
|
||||||
var p = (n + e) * 100.0 / t,
|
this.tab[nfile].cb = blocktab;
|
||||||
td = new Date().getTime() - t0,
|
|
||||||
pp = (td / 1000) / p,
|
var bd = 0;
|
||||||
spd = (sz / 100) / pp,
|
for (var a = 0; a < blocktab.length; a++)
|
||||||
eta = pp * (100 - p);
|
bd += blocktab[a];
|
||||||
|
|
||||||
|
this.tab[nfile].bd = bd;
|
||||||
|
this.tab[nfile].bd0 = bd;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.perc = function (bd, bd0, sz, t0) {
|
||||||
|
var td = new Date().getTime() - t0,
|
||||||
|
p = bd * 100.0 / sz,
|
||||||
|
nb = bd - bd0,
|
||||||
|
spd = nb / (td / 1000),
|
||||||
|
eta = (sz - bd) / spd;
|
||||||
|
|
||||||
return [p, s2ms(eta), spd / (1024 * 1024)];
|
return [p, s2ms(eta), spd / (1024 * 1024)];
|
||||||
};
|
};
|
||||||
|
|
||||||
this.hashed = function (fobj) {
|
this.hashed = function (fobj) {
|
||||||
var fo = this.tab[fobj.n];
|
var fo = this.tab[fobj.n];
|
||||||
fo.nh++;
|
var nb = fo.bt * (++fo.nh / fo.cb.length);
|
||||||
var p = this.perc(fo.nh, fo.pa.length, 0, fobj.size, fobj.t1);
|
var p = this.perc(nb, 0, fobj.size, fobj.t1);
|
||||||
fo.hp = '{0}%, {1}, {2} MB/s'.format(
|
fo.hp = '{0}%, {1}, {2} MB/s'.format(
|
||||||
p[0].toFixed(2), p[1], p[2].toFixed(2)
|
p[0].toFixed(2), p[1], p[2].toFixed(2)
|
||||||
);
|
);
|
||||||
|
@ -219,26 +232,13 @@ function U2pvis(act, btns) {
|
||||||
obj.style.background = 'linear-gradient(90deg, #025, #06a ' + o1 + '%, #09d ' + o2 + '%, #333 ' + o3 + '%, #333 99%, #777)';
|
obj.style.background = 'linear-gradient(90deg, #025, #06a ' + o1 + '%, #09d ' + o2 + '%, #333 ' + o3 + '%, #333 99%, #777)';
|
||||||
};
|
};
|
||||||
|
|
||||||
this.prog = function (fobj, nchunk, percent) {
|
this.prog = function (fobj, nchunk, cbd) {
|
||||||
var fo = this.tab[fobj.n], pb = fo.pb;
|
var fo = this.tab[fobj.n];
|
||||||
var i = pb.indexOf(nchunk);
|
var delta = cbd - fo.cb[nchunk];
|
||||||
fo.pa[nchunk] = percent;
|
fo.cb[nchunk] = cbd;
|
||||||
if (percent == 101) {
|
fo.bd += delta;
|
||||||
fo.nd++;
|
|
||||||
if (i >= 0)
|
|
||||||
pb.splice(i);
|
|
||||||
}
|
|
||||||
else if (i == -1) {
|
|
||||||
pb.push(nchunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
var extra = 0;
|
var p = this.perc(fo.bd, fo.bd0, fo.bt, fobj.t3);
|
||||||
for (var a = 0; a < pb.length; a++)
|
|
||||||
extra += fo.pa[a];
|
|
||||||
|
|
||||||
extra /= fo.pa.length;
|
|
||||||
|
|
||||||
var p = this.perc(fo.nd, fo.pa.length, extra, fobj.size, fobj.t3);
|
|
||||||
fo.hp = '{0}%, {1}, {2} MB/s'.format(
|
fo.hp = '{0}%, {1}, {2} MB/s'.format(
|
||||||
p[0].toFixed(2), p[1], p[2].toFixed(2)
|
p[0].toFixed(2), p[1], p[2].toFixed(2)
|
||||||
);
|
);
|
||||||
|
@ -690,7 +690,7 @@ function up2k_init(have_crypto) {
|
||||||
esc(uricom_dec(entry.purl)[0] + entry.name)).join(' '),
|
esc(uricom_dec(entry.purl)[0] + entry.name)).join(' '),
|
||||||
'📐 hash',
|
'📐 hash',
|
||||||
''
|
''
|
||||||
]);
|
], fobj.size);
|
||||||
st.files.push(entry);
|
st.files.push(entry);
|
||||||
st.todo.hash.push(entry);
|
st.todo.hash.push(entry);
|
||||||
}
|
}
|
||||||
|
@ -1106,6 +1106,14 @@ function up2k_init(have_crypto) {
|
||||||
pvis.seth(t.n, 0, linksplit(esc(t.purl + t.name)).join(' '));
|
pvis.seth(t.n, 0, linksplit(esc(t.purl + t.name)).join(' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var chunksize = get_chunksize(t.size);
|
||||||
|
var cdr_idx = Math.ceil(t.size / chunksize) - 1;
|
||||||
|
var cdr_sz = (t.size % chunksize) || chunksize;
|
||||||
|
var cbd = [];
|
||||||
|
for (var a = 0; a <= cdr_idx; a++) {
|
||||||
|
cbd.push(a == cdr_idx ? cdr_sz : chunksize);
|
||||||
|
}
|
||||||
|
|
||||||
t.postlist = [];
|
t.postlist = [];
|
||||||
t.wark = response.wark;
|
t.wark = response.wark;
|
||||||
var missing = response.hash;
|
var missing = response.hash;
|
||||||
|
@ -1116,8 +1124,12 @@ function up2k_init(have_crypto) {
|
||||||
missing[a], JSON.stringify(t)));
|
missing[a], JSON.stringify(t)));
|
||||||
|
|
||||||
t.postlist.push(idx);
|
t.postlist.push(idx);
|
||||||
|
cbd[idx] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pvis.setat(t.n, cbd);
|
||||||
|
pvis.prog(t, 0, cbd[0]);
|
||||||
|
|
||||||
var done = true;
|
var done = true;
|
||||||
var msg = '🎷🐛';
|
var msg = '🎷🐛';
|
||||||
if (t.postlist.length > 0) {
|
if (t.postlist.length > 0) {
|
||||||
|
@ -1226,12 +1238,11 @@ function up2k_init(have_crypto) {
|
||||||
reader.onload = function (e) {
|
reader.onload = function (e) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.upload.onprogress = function (xev) {
|
xhr.upload.onprogress = function (xev) {
|
||||||
var perc = xev.loaded / (cdr - car) * 100;
|
pvis.prog(t, npart, xev.loaded);
|
||||||
pvis.prog(t, npart, perc, t);
|
|
||||||
};
|
};
|
||||||
xhr.onload = function (xev) {
|
xhr.onload = function (xev) {
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
pvis.prog(t, npart, 101, t);
|
pvis.prog(t, npart, cdr - car);
|
||||||
st.bytes.uploaded += cdr - car;
|
st.bytes.uploaded += cdr - car;
|
||||||
t.bytes_uploaded += cdr - car;
|
t.bytes_uploaded += cdr - car;
|
||||||
st.busy.upload.splice(st.busy.upload.indexOf(upt), 1);
|
st.busy.upload.splice(st.busy.upload.indexOf(upt), 1);
|
||||||
|
|
Loading…
Reference in a new issue