From 65bc644d032fa8d01c6ce291cb1bb1d98873ed3a Mon Sep 17 00:00:00 2001 From: Bernt Christian Egeland Date: Sun, 15 Jan 2023 16:39:03 +0100 Subject: [PATCH] Rework storage page to show sizes with relevant units (#5093) * new getUnitSize function * check if isNaN --- web/src/routes/Storage.jsx | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/web/src/routes/Storage.jsx b/web/src/routes/Storage.jsx index 6dfc9165a..06976ca76 100644 --- a/web/src/routes/Storage.jsx +++ b/web/src/routes/Storage.jsx @@ -22,6 +22,13 @@ export default function Storage() { return ; } + const getUnitSize = (MB) => { + if (isNaN(MB) || MB < 0) return 'Invalid number'; + if (MB < 1024) return `${MB} MB`; + + return `${(MB / 1024).toFixed(2)} GB`; + }; + let storage_usage; if ( service && @@ -31,13 +38,13 @@ export default function Storage() { Recordings - {service['storage']['/media/frigate/recordings']['used']} - {service['storage']['/media/frigate/recordings']['total']} + {getUnitSize(service['storage']['/media/frigate/recordings']['used'])} + {getUnitSize(service['storage']['/media/frigate/recordings']['total'])} Snapshots - {service['storage']['/media/frigate/clips']['used']} - {service['storage']['/media/frigate/clips']['total']} + {getUnitSize(service['storage']['/media/frigate/clips']['used'])} + {getUnitSize(service['storage']['/media/frigate/clips']['total'])} ); @@ -46,8 +53,8 @@ export default function Storage() { Recordings & Snapshots - {service['storage']['/media/frigate/recordings']['used']} - {service['storage']['/media/frigate/recordings']['total']} + {getUnitSize(service['storage']['/media/frigate/recordings']['used'])} + {getUnitSize(service['storage']['/media/frigate/recordings']['total'])} ); @@ -67,8 +74,8 @@ export default function Storage() { Location - Used MB - Total MB + Used + Total {storage_usage} @@ -82,20 +89,20 @@ export default function Storage() { Location - Used MB - Total MB + Used + Total /dev/shm - {service['storage']['/dev/shm']['used']} - {service['storage']['/dev/shm']['total']} + {getUnitSize(service['storage']['/dev/shm']['used'])} + {getUnitSize(service['storage']['/dev/shm']['total'])} /tmp/cache - {service['storage']['/tmp/cache']['used']} - {service['storage']['/tmp/cache']['total']} + {getUnitSize(service['storage']['/tmp/cache']['used'])} + {getUnitSize(service['storage']['/tmp/cache']['total'])} @@ -121,7 +128,7 @@ export default function Storage() { {Math.round(camera['usage_percent'] ?? 0)}% - {camera['bandwidth'] ? camera['bandwidth'] : 'Calculating...'} MB/hr + {camera['bandwidth'] ? getUnitSize(camera['bandwidth']) : 'Calculating...'}/hr