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