mirror of
https://github.com/OpenListTeam/OpenList-Frontend.git
synced 2026-03-13 11:20:24 +00:00
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:
@@ -56,6 +56,7 @@ export type ArchiveMeta = {
|
||||
export type MountDetails = {
|
||||
total_space?: number
|
||||
free_space?: number
|
||||
used_space?: number
|
||||
driver_name: string
|
||||
}
|
||||
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user