Enhancement: Allow Disk Resources Widget For Combined Disk Mounts
This commit is contained in:
parent
c267eeabf8
commit
1133891842
@ -31,15 +31,19 @@ export default function Disk({ options, expanded, diskUnits, refresh = 1500 }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// data.drive.used not accurate?
|
// Calculate the total size and available space from the data.drive array
|
||||||
const percent = Math.round(((data.drive.size - data.drive.available) / data.drive.size) * 100);
|
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 (
|
return (
|
||||||
<Resource
|
<Resource
|
||||||
icon={FiHardDrive}
|
icon={FiHardDrive}
|
||||||
value={t(diskUnitsName, { value: data.drive.available })}
|
value={t(diskUnitsName, { value: totalAvailable })}
|
||||||
label={t("resources.free")}
|
label={t("resources.free")}
|
||||||
expandedValue={t(diskUnitsName, { value: data.drive.size })}
|
expandedValue={t(diskUnitsName, { value: totalSize })}
|
||||||
expandedLabel={t("resources.total")}
|
expandedLabel={t("resources.total")}
|
||||||
percentage={percent}
|
percentage={percent}
|
||||||
expanded={expanded}
|
expanded={expanded}
|
||||||
|
|||||||
@ -23,9 +23,18 @@ export default async function handler(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fsSize = await si.fsSize();
|
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({
|
return res.status(200).json({
|
||||||
drive: fsSize.find((fs) => fs.mount === target) ?? fsSize.find((fs) => fs.mount === "/"),
|
drive: driveData,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user