Enhancement: Allow Disk Resources Widget For Combined Disk Mounts

This commit is contained in:
jeremyjohn 2024-06-01 01:17:39 +08:00
parent c267eeabf8
commit 1133891842
2 changed files with 18 additions and 5 deletions

View File

@ -31,15 +31,19 @@ export default function Disk({ options, expanded, diskUnits, refresh = 1500 }) {
);
}
// data.drive.used not accurate?
const percent = Math.round(((data.drive.size - data.drive.available) / data.drive.size) * 100);
// Calculate the total size and available space from the data.drive array
const totalSize = data.drive.reduce((acc, drive) => acc + drive.size, 0);
const totalAvailable = data.drive.reduce((acc, drive) => acc + drive.available, 0);
// Calculate the percentage of used space
const percent = Math.round(((totalSize - totalAvailable) / totalSize) * 100);
return (
<Resource
icon={FiHardDrive}
value={t(diskUnitsName, { value: data.drive.available })}
value={t(diskUnitsName, { value: totalAvailable })}
label={t("resources.free")}
expandedValue={t(diskUnitsName, { value: data.drive.size })}
expandedValue={t(diskUnitsName, { value: totalSize })}
expandedLabel={t("resources.total")}
percentage={percent}
expanded={expanded}

View File

@ -23,9 +23,18 @@ export default async function handler(req, res) {
}
const fsSize = await si.fsSize();
let driveData;
if (target === "/") {
const rootTarget = fsSize.find((fs) => fs.mount === "/");
driveData = rootTarget ?? [rootTarget];
} else {
const foundTarget = fsSize.find((fs) => fs.mount === target);
driveData = foundTarget ? [foundTarget] : fsSize;
}
return res.status(200).json({
drive: fsSize.find((fs) => fs.mount === target) ?? fsSize.find((fs) => fs.mount === "/"),
drive: driveData,
});
}