diff --git a/src/types/obj.ts b/src/types/obj.ts index c523530..2356cfc 100644 --- a/src/types/obj.ts +++ b/src/types/obj.ts @@ -56,6 +56,7 @@ export type ArchiveMeta = { export type MountDetails = { total_space?: number free_space?: number + used_space?: number driver_name: string } diff --git a/src/utils/storage.ts b/src/utils/storage.ts index 15d37da..d884374 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -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) => {