new getUnitSize function

This commit is contained in:
Bernt Christian Egeland 2023-01-14 23:08:54 +01:00
parent 60b2315028
commit dee641a2be

View File

@ -22,6 +22,12 @@ export default function Storage() {
return <ActivityIndicator />; return <ActivityIndicator />;
} }
const getUnitSize = (MB) => {
if (MB < 1024) return `${MB} MB`;
return `${(MB / 1024).toFixed(2)} GB`;
};
let storage_usage; let storage_usage;
if ( if (
service && service &&
@ -31,13 +37,13 @@ export default function Storage() {
<Fragment> <Fragment>
<Tr> <Tr>
<Td>Recordings</Td> <Td>Recordings</Td>
<Td>{service['storage']['/media/frigate/recordings']['used']}</Td> <Td>{getUnitSize(service['storage']['/media/frigate/recordings']['used'])}</Td>
<Td>{service['storage']['/media/frigate/recordings']['total']}</Td> <Td>{getUnitSize(service['storage']['/media/frigate/recordings']['total'])}</Td>
</Tr> </Tr>
<Tr> <Tr>
<Td>Snapshots</Td> <Td>Snapshots</Td>
<Td>{service['storage']['/media/frigate/clips']['used']}</Td> <Td>{getUnitSize(service['storage']['/media/frigate/clips']['used'])}</Td>
<Td>{service['storage']['/media/frigate/clips']['total']}</Td> <Td>{getUnitSize(service['storage']['/media/frigate/clips']['total'])}</Td>
</Tr> </Tr>
</Fragment> </Fragment>
); );
@ -46,8 +52,8 @@ export default function Storage() {
<Fragment> <Fragment>
<Tr> <Tr>
<Td>Recordings & Snapshots</Td> <Td>Recordings & Snapshots</Td>
<Td>{service['storage']['/media/frigate/recordings']['used']}</Td> <Td>{getUnitSize(service['storage']['/media/frigate/recordings']['used'])}</Td>
<Td>{service['storage']['/media/frigate/recordings']['total']}</Td> <Td>{getUnitSize(service['storage']['/media/frigate/recordings']['total'])}</Td>
</Tr> </Tr>
</Fragment> </Fragment>
); );
@ -67,8 +73,8 @@ export default function Storage() {
<Thead> <Thead>
<Tr> <Tr>
<Th>Location</Th> <Th>Location</Th>
<Th>Used MB</Th> <Th>Used</Th>
<Th>Total MB</Th> <Th>Total</Th>
</Tr> </Tr>
</Thead> </Thead>
<Tbody>{storage_usage}</Tbody> <Tbody>{storage_usage}</Tbody>
@ -82,20 +88,20 @@ export default function Storage() {
<Thead> <Thead>
<Tr> <Tr>
<Th>Location</Th> <Th>Location</Th>
<Th>Used MB</Th> <Th>Used</Th>
<Th>Total MB</Th> <Th>Total</Th>
</Tr> </Tr>
</Thead> </Thead>
<Tbody> <Tbody>
<Tr> <Tr>
<Td>/dev/shm</Td> <Td>/dev/shm</Td>
<Td>{service['storage']['/dev/shm']['used']}</Td> <Td>{getUnitSize(service['storage']['/dev/shm']['used'])}</Td>
<Td>{service['storage']['/dev/shm']['total']}</Td> <Td>{getUnitSize(service['storage']['/dev/shm']['total'])}</Td>
</Tr> </Tr>
<Tr> <Tr>
<Td>/tmp/cache</Td> <Td>/tmp/cache</Td>
<Td>{service['storage']['/tmp/cache']['used']}</Td> <Td>{getUnitSize(service['storage']['/tmp/cache']['used'])}</Td>
<Td>{service['storage']['/tmp/cache']['total']}</Td> <Td>{getUnitSize(service['storage']['/tmp/cache']['total'])}</Td>
</Tr> </Tr>
</Tbody> </Tbody>
</Table> </Table>
@ -121,7 +127,7 @@ export default function Storage() {
<Tbody> <Tbody>
<Tr> <Tr>
<Td>{Math.round(camera['usage_percent'] ?? 0)}%</Td> <Td>{Math.round(camera['usage_percent'] ?? 0)}%</Td>
<Td>{camera['bandwidth'] ? camera['bandwidth'] : 'Calculating...'} MB/hr</Td> <Td>{camera['bandwidth'] ? getUnitSize(camera['bandwidth']) : 'Calculating...'}/hr</Td>
</Tr> </Tr>
</Tbody> </Tbody>
</Table> </Table>