update 1.2.2.2 beta

This commit is contained in:
MacRimi
2026-06-24 23:40:22 +02:00
parent 87a29f324b
commit 202068124b
9 changed files with 148 additions and 112 deletions
+30
View File
@@ -0,0 +1,30 @@
// Shared classifier for physical-disk type. Lives here because the
// Storage page and the Hardware page used to ship their own copies
// and silently drifted — old SSDs (e.g. OCZ-SOLID2) that don't expose
// a SMART rotation rate fell through Hardware's HDD-as-default branch
// and got mislabelled, while the Storage page got it right.
//
// Backend convention for `rotation_rate`:
// undefined / null / 0 → SSD (no platters reported)
// -1 → HDD detected via /sys rotational flag,
// but the drive doesn't expose RPM
// > 0 → HDD with known RPM
// string "Solid State" → SSD (smartctl wording on a few vendors)
export type DiskType = "NVMe" | "SSD" | "HDD"
export function getDiskType(
diskName: string,
rotationRate: number | string | null | undefined,
): DiskType {
if (diskName.startsWith("nvme")) return "NVMe"
if (rotationRate === -1) return "HDD"
if (typeof rotationRate === "string") {
if (rotationRate.includes("Solid State")) return "SSD"
const parsed = Number.parseInt(rotationRate, 10)
if (Number.isNaN(parsed) || parsed === 0) return "SSD"
return "HDD"
}
if (rotationRate == null || rotationRate === 0) return "SSD"
return "HDD"
}
+17
View File
@@ -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`
}