From 4042cf3118e9330e9617e5345bcf954572dd0c7a Mon Sep 17 00:00:00 2001 From: Mihail Slobodyanuk Date: Tue, 20 Dec 2022 19:04:22 +0200 Subject: [PATCH] RIVM-16 --- contrib/ui/mesh-ui/ui/assets/mesh-ui-es5.js | 9 +++++---- contrib/ui/mesh-ui/ui/assets/mesh-ui.js | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/contrib/ui/mesh-ui/ui/assets/mesh-ui-es5.js b/contrib/ui/mesh-ui/ui/assets/mesh-ui-es5.js index 53cc59ad..3a1c20d0 100644 --- a/contrib/ui/mesh-ui/ui/assets/mesh-ui-es5.js +++ b/contrib/ui/mesh-ui/ui/assets/mesh-ui-es5.js @@ -232,8 +232,9 @@ function togglePrivKeyVisibility() { } function humanReadableSpeed(speed) { - var i = speed == 0 ? 0 : Math.floor(Math.log(speed) / Math.log(1024)); - return (speed / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['Bps', 'kBps', 'MBps', 'GBps', 'TBps'][i]; + if (speed < 0) return "? B/s"; + var i = speed < 1 ? 0 : Math.floor(Math.log(speed) / Math.log(1024)); + return (speed / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['bps', 'kbps', 'Mbps', 'Gbps', 'Tbps'][i]; } var ui = ui || { @@ -348,8 +349,8 @@ ui.updateSpeed = function (peers) { ui._rsbytes = rsbytes; } else { delete ui._rsbytes; - $("dn_speed").innerText = "? Bs"; - $("up_speed").innerText = "? Bs"; + $("dn_speed").innerText = humanReadableSpeed(-1); + $("up_speed").innerText = humanReadableSpeed(-1); } }; diff --git a/contrib/ui/mesh-ui/ui/assets/mesh-ui.js b/contrib/ui/mesh-ui/ui/assets/mesh-ui.js index 294b4f3d..37f17914 100644 --- a/contrib/ui/mesh-ui/ui/assets/mesh-ui.js +++ b/contrib/ui/mesh-ui/ui/assets/mesh-ui.js @@ -225,8 +225,9 @@ function togglePrivKeyVisibility() { } function humanReadableSpeed(speed) { - var i = speed == 0 ? 0 : Math.floor(Math.log(speed) / Math.log(1024)); - return (speed / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['Bps', 'kBps', 'MBps', 'GBps', 'TBps'][i]; + if (speed < 0) return "? B/s"; + var i = speed < 1 ? 0 : Math.floor(Math.log(speed) / Math.log(1024)); + return (speed / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['bps', 'kbps', 'Mbps', 'Gbps', 'Tbps'][i]; } var ui = ui || { @@ -327,8 +328,8 @@ ui.updateSpeed = peers => { ui._rsbytes = rsbytes; } else { delete ui._rsbytes; - $("dn_speed").innerText = "? Bs"; - $("up_speed").innerText = "? Bs"; + $("dn_speed").innerText = humanReadableSpeed(-1); + $("up_speed").innerText = humanReadableSpeed(-1); } }