Track per-device traffic totals and recover inventory state
Build and Deploy Gateway / build-and-push (push) Successful in 15s
Build and Deploy Gateway / deploy (push) Successful in 13s

This commit is contained in:
2026-08-07 15:24:54 +03:00
parent e774486b99
commit 307ad02cd7
13 changed files with 842 additions and 96 deletions
+34
View File
@@ -10,6 +10,40 @@ export function formatBytes(value) {
return `${size.toFixed(index === 0 ? 0 : 1)} ${units[index]}`;
}
const BYTE_STRING_PATTERN = /^\d+$/;
export function byteString(value) {
const normalized = String(value ?? '0');
return BYTE_STRING_PATTERN.test(normalized) ? BigInt(normalized) : 0n;
}
export function formatByteString(value) {
const bytes = byteString(value);
const units = ['Б', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ', 'ЭБ'];
let unit = 0;
let divisor = 1n;
while (bytes >= divisor * 1024n && unit < units.length - 1) {
divisor *= 1024n;
unit += 1;
}
if (unit === 0) return `${bytes} ${units[unit]}`;
const tenths = (bytes * 10n + divisor / 2n) / divisor;
return `${tenths / 10n},${tenths % 10n} ${units[unit]}`;
}
export function sortDevicesByTraffic(devices, direction = 'desc') {
const factor = direction === 'asc' ? 1 : -1;
return (Array.isArray(devices) ? devices : [])
.map((device, index) => ({ device, index }))
.sort((left, right) => {
const leftTotal = byteString(left.device.uploadBytes) + byteString(left.device.downloadBytes);
const rightTotal = byteString(right.device.uploadBytes) + byteString(right.device.downloadBytes);
if (leftTotal === rightTotal) return left.index - right.index;
return (leftTotal < rightTotal ? -1 : 1) * factor;
})
.map(({ device }) => device);
}
export function formatRelative(iso) {
if (!iso) return "";
const ts = new Date(iso).getTime();