feat: supports show connection detail

This commit is contained in:
GyDi
2023-08-05 16:52:14 +08:00
parent 53a207e859
commit 2ce944034d
6 changed files with 173 additions and 176 deletions

View File

@@ -1,6 +1,7 @@
const UNITS = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const parseTraffic = (num: number) => {
const parseTraffic = (num?: number) => {
if (typeof num !== "number") return ["NaN", ""];
if (num < 1000) return [`${Math.round(num)}`, "B"];
const exp = Math.min(Math.floor(Math.log2(num) / 10), UNITS.length - 1);
const dat = num / Math.pow(1024, exp);