✏️ Add size for backup-ed snapshot in detail modal

This commit is contained in:
Sebastien Clement 2020-11-04 12:30:01 +01:00
parent 9a581d24de
commit 2c506c2e69
3 changed files with 31 additions and 2 deletions

View File

@ -7,6 +7,7 @@ const webdav = new WebdavTools().getInstance();
const settingsTools = require('../tools/settingsTools');
const pathTools = require('../tools/pathTools');
const hassioApiTools = require('../tools/hassioApiTools');
const humanFileSize = require('../tools/toolbox').humanFileSize;
const cronTools = require('../tools/cronTools');
@ -58,7 +59,7 @@ router.get('/formated-backup-manual', function(req, res, next) {
else
return -1;
})
res.render('backupSnaps',{backups: contents, moment: moment});
res.render('backupSnaps',{backups: contents, moment: moment, humanFileSize: humanFileSize});
}).catch(()=>{
res.send();
});
@ -75,7 +76,7 @@ router.get('/formated-backup-auto', function(req, res, next) {
else
return -1;
})
res.render('backupSnaps',{backups: contents, moment: moment});
res.render('backupSnaps',{backups: contents, moment: moment, humanFileSize: humanFileSize});
}).catch(()=>{
res.send();
});

View File

@ -0,0 +1,23 @@
// Found on Stackoverflow, perfect code :D https://stackoverflow.com/a/14919494/8654475
function humanFileSize(bytes, si=false, dp=1) {
const thresh = si ? 1000 : 1024;
if (Math.abs(bytes) < thresh) {
return bytes + ' B';
}
const units = si ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
let u = -1;
const r = 10**dp;
do {
bytes /= thresh;
++u;
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
return bytes.toFixed(dp) + ' ' + units[u];
}
exports.humanFileSize = humanFileSize

View File

@ -32,6 +32,11 @@
value="<%=moment(backups[index].lastmod).format('MMM D, YYYY HH:mm')%>" />
<label for="date-<%=backups[index].etag%>" class="white-text active">Date</label>
</div>
<div class="input-field col s12">
<input disabled type="text" id="size-<%=backups[index].etag%>"
value="<%=humanFileSize(backups[index].size, false)%>" />
<label for="size-<%=backups[index].etag%>" class="white-text active">Size</label>
</div>
</div>
</div>
<div class="modal-footer blue-grey darken-4">