From 43773f2c7e29d451a82288d761d959bf6f8ba317 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 22 Apr 2026 19:31:47 +0000 Subject: [PATCH] filesize units 6/7; closes #1389 --- copyparty/__main__.py | 2 +- copyparty/web/browser.js | 24 ++++++++++++++---------- copyparty/web/up2k.js | 12 ++++++------ copyparty/web/util.js | 39 ++++++++++++++++++++++++++++++++++----- 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 7cd98005..f9b60ca4 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1889,7 +1889,7 @@ def add_ui(ap, retry: int): ap2.add_argument("--grid", action="store_true", help="show grid/thumbnails by default (volflag=grid)") ap2.add_argument("--gsel", action="store_true", help="select files in grid by ctrl-click (volflag=gsel)") ap2.add_argument("--localtime", action="store_true", help="default to local timezone instead of UTC") - ap2.add_argument("--ui-filesz", metavar="FMT", type=u, default="1", help="default filesize format; one of these: 0, 1, 2, 2c, 3, 3c, 4, 4c, 5, 5c, fuzzy (see UI)") + ap2.add_argument("--ui-filesz", metavar="FMT", type=u, default="1", help="default filesize format; one of these: 0, 1, 2, 2c, 3, 3c, 4, 4c, 5, 5c, 6, 6c, 7, 7c, fuzzy (see UI)") ap2.add_argument("--gauto", metavar="PERCENT", type=int, default=0, help="switch to gridview if more than \033[33mPERCENT\033[0m of files are pics/vids; 0=disabled") ap2.add_argument("--rcm", metavar="TXT", default="yy", help="rightclick-menu; two yes/no options: 1st y/n is enable-custom-menu, 2nd y/n is enable-double") ap2.add_argument("--lang", metavar="LANG", type=u, default="eng", help="language, for example \033[32meng\033[0m / \033[32mnor\033[0m / ...") diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 84323b63..57685423 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -999,16 +999,20 @@ ebi('op_cfg').innerHTML = ( '
\n' + '

' + L.cl_hfsz + '

\n' + '
\n' + '
\n' + diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 21a6dad0..4750765b 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -269,7 +269,7 @@ function U2pvis(act, btns, uc, st) { nb = fo.bt * (++fo.nh / fo.cb.length), p = r.perc(nb, 0, fobj.size, fobj.t_hashing); - fo.hp = f2f(p[0], 2) + '%, ' + p[1] + ', ' + f2f(p[2], 2) + ' MB/s'; + fo.hp = f2f(p[0], 2) + '%, ' + p[1] + ', ' + f2f(p[2], 2) + ' MiB/s'; if (!r.is_act(fo.in)) return; @@ -289,7 +289,7 @@ function U2pvis(act, btns, uc, st) { return; var p = r.perc(fo.bd, fo.bd0, fo.bt, fobj.t_uploading); - fo.hp = f2f(p[0], 2) + '%, ' + p[1] + ', ' + f2f(p[2], 2) + ' MB/s'; + fo.hp = f2f(p[0], 2) + '%, ' + p[1] + ', ' + f2f(p[2], 2) + ' MiB/s'; if (!r.is_act(fo.in)) return; @@ -1634,7 +1634,7 @@ function up2k_init(subtle) { } if (!nhash) { - var h = L.u_etadone.format(humansize(st.bytes.hashed), pvis.ctr.ok + pvis.ctr.ng); + var h = L.u_etadone.format(humansize(st.bytes.hashed, 2), pvis.ctr.ok + pvis.ctr.ng); if (st.eta.h !== h) { st.eta.h = ebi('u2etah').innerHTML = h; console.log('{0} hash, {1} up, {2} busy'.format( @@ -1645,7 +1645,7 @@ function up2k_init(subtle) { } if (!nsend && !nhash) { - var h = L.u_etadone.format(humansize(st.bytes.uploaded), pvis.ctr.ok + pvis.ctr.ng); + var h = L.u_etadone.format(humansize(st.bytes.uploaded, 2), pvis.ctr.ok + pvis.ctr.ng); if (st.eta.u !== h) st.eta.u = ebi('u2etau').innerHTML = h; @@ -1710,7 +1710,7 @@ function up2k_init(subtle) { donut.eta = eta; st.eta[eid] = '{0}, {1}/s, {2}'.format( - humansize(rem), humansize(bps, 1), humantime(eta)); + humansize(rem, 2), humansize(bps, 1), humantime(eta)); if (!etaskip) ebi(hid).innerHTML = st.eta[eid]; @@ -2691,7 +2691,7 @@ function up2k_init(subtle) { 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.); - pvis.seth(t.n, 2, 'hash {0}, up {1} MB/s'.format( + pvis.seth(t.n, 2, 'hash {0}, up {1} MiB/s'.format( f2f(spd1, 2), !isNum(spd2) ? '--' : f2f(spd2, 2))); pvis.move(t.n, 'ok'); diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 0476e203..8870f22e 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -979,17 +979,24 @@ function f2f(val, nd) { } -var HSZ_U = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; -function humansize(b, terse) { +var HSZ_U = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']; +var HSZ_U2 = ['B', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi']; +var HSZ_UD = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; +function humansize(b, tersity) { var i = 0; while (b >= 1000 && i < 5) { b /= 1024; i += 1; } return (f2f(b, b >= 100 ? 0 : b >= 10 ? 1 : 2) + - ' ' + (terse ? HSZ_U[i].charAt(0) : HSZ_U[i])); + ' ' + (tersity ? HSZ_U[i].slice(0, tersity) : HSZ_U[i])); } function humansize_su(b) { var i = 0; while (b >= 1000 && i < 5) { b /= 1024; i += 1; } - return [b, HSZ_U[i]]; + return [b, HSZ_U2[i]]; +} +function humansize_sud(b) { + var i = 0; + while (b >= 1000 && i < 5) { b /= 1000; i += 1; } + return [b, HSZ_UD[i]]; } function humansize_0(b) { return '' + b; @@ -1013,6 +1020,14 @@ function humansize_5g(b) { var z = humansize_su(b), u = z[1]; b = z[0]; return [parseFloat(b.toFixed(b >= 10 ? 0 : 1)) + ' ' + u, u.charAt(0)]; } +function humansize_6g(b) { + var z = humansize_sud(b), u = z[1]; b = z[0]; + return [parseFloat(b.toFixed(b >= 100 ? 0 : b >= 10 ? 1 : 2)) + ' ' + u, u.charAt(0)]; +} +function humansize_7g(b) { + var z = humansize_sud(b), u = z[1]; b = z[0]; + return [parseFloat(b.toFixed(b >= 10 ? 0 : 1)) + ' ' + u, u.charAt(0)]; +} function humansize_2(b) { return humansize_2g(b)[0]; } @@ -1025,6 +1040,12 @@ function humansize_4(b) { function humansize_5(b) { return humansize_5g(b)[0]; } +function humansize_6(b) { + return humansize_6g(b)[0]; +} +function humansize_7(b) { + return humansize_7g(b)[0]; +} function humansize_2c(b) { var v = humansize_2g(b); return '' + v[0] + ''; @@ -1041,6 +1062,14 @@ function humansize_5c(b) { var v = humansize_5g(b); return '' + v[0] + ''; } +function humansize_6c(b) { + var v = humansize_6g(b); + return '' + v[0] + ''; +} +function humansize_7c(b) { + var v = humansize_7g(b); + return '' + v[0] + ''; +} function humansize_fuzzy(b) { if (b <= 0) return "yes"; if (b <= 80) return "hullkort"; @@ -1063,7 +1092,7 @@ function humansize_fuzzy(b) { if (b <= 50050000000) return "BD-DL"; return "LTO"; } -var humansize_fmts = ['0', '1', '2', '2c', '3', '3c', '4', '4c', '5', '5c', 'fuzzy']; +var humansize_fmts = ['0', '1', '2', '2c', '3', '3c', '4', '4c', '5', '5c', '6', '6c', '7', '7c', 'fuzzy']; window.filesizefun = (function () { var v = sread('fszfmt', humansize_fmts); return window['humansize_' + (v || window.dfszf)] || humansize_1;