fix: added failsafe to available disk stats

This commit is contained in:
Bobby Wibowo 2021-01-29 22:44:58 +07:00
parent 5842793d47
commit a752bb89e8
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -725,14 +725,19 @@ self.stats = async (req, res, next) => {
const fsSize = await si.fsSize()
for (const fs of fsSize) {
stats[data.title][`${fs.fs} (${fs.type}) on ${fs.mount}`] = {
const obj = {
value: {
total: fs.size,
used: fs.used,
available: fs.available
used: fs.used
},
type: 'byteUsage'
}
// "available" is a new attribute in systeminformation v5, only tested on Linux,
// so add an if-check just in case its availability is limited in other platforms
if (typeof fs.available === 'number') {
obj.value.available = fs.available
}
stats[data.title][`${fs.fs} (${fs.type}) on ${fs.mount}`] = obj
}
// Update cache