mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-08-02 05:46:21 +00:00
update 1.2.2.2 beta
This commit is contained in:
@@ -19,3 +19,20 @@ export function formatStorage(sizeInGB: number): string {
|
||||
return `${tb % 1 === 0 ? tb.toFixed(0) : tb.toFixed(1)} TB`
|
||||
}
|
||||
}
|
||||
|
||||
// Byte-aware formatter. Scales B → KB → MB → GB → TB. Use when the
|
||||
// raw value comes in bytes (log file sizes from os.path.getsize(),
|
||||
// PBS / Borg datastore capacity reported by the backend in bytes).
|
||||
// The Backups page used to ship its own copy that capped at GB, so a
|
||||
// 7 TB datastore showed up as "7311.55 GB" — extracted here so it
|
||||
// can't drift again.
|
||||
export function formatBytes(n: number): string {
|
||||
if (!Number.isFinite(n) || n < 0) return "—"
|
||||
if (n < 1024) return `${n} B`
|
||||
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
|
||||
if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`
|
||||
if (n < 1024 * 1024 * 1024 * 1024) {
|
||||
return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`
|
||||
}
|
||||
return `${(n / (1024 * 1024 * 1024 * 1024)).toFixed(2)} TB`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user