fix(fs/storage-details): use used space (#355)

* fix(fs/storage-details): show used space

* Apply suggestion

Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>

---------

Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
Co-authored-by: MadDogOwner <xiaoran@xrgzs.top>
This commit is contained in:
KirCute
2026-01-08 11:07:55 +08:00
committed by GitHub
parent 3a9e411ae1
commit db9803b6a7
2 changed files with 8 additions and 6 deletions

View File

@@ -56,6 +56,7 @@ export type ArchiveMeta = {
export type MountDetails = {
total_space?: number
free_space?: number
used_space?: number
driver_name: string
}

View File

@@ -1,12 +1,12 @@
import { MountDetails } from "~/types"
export const showDiskUsage = (details?: MountDetails) => {
return details?.total_space > 0
return details?.total_space && details?.total_space > 0
}
export const toReadableUsage = (details: MountDetails) => {
let total = details.total_space!
let used = total - details.free_space!
let used = details.used_space!
const units = ["B", "K", "M", "G", "T", "P", "E"]
const k = 1024
let unit_i = 0
@@ -19,10 +19,11 @@ export const toReadableUsage = (details: MountDetails) => {
}
export const usedPercentage = (details: MountDetails) => {
return (
((details.total_space! - details.free_space!) / details.total_space!) *
100.0
)
if (!details.total_space || details.total_space <= 0) return 0.0
const total = details.total_space
const used =
!details.used_space || details.used_space <= 0 ? 0.0 : details.used_space
return used >= total ? 100.0 : (used / total) * 100.0
}
export const nearlyFull = (details: MountDetails) => {