Skip to content

Commit

Permalink
✏️ Add size for backup-ed snapshot in detail modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebclem committed Nov 4, 2020
1 parent 9a581d2 commit 2c506c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions nextcloud_backup/rootfs/opt/nextcloud_backup/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand Down
23 changes: 23 additions & 0 deletions nextcloud_backup/rootfs/opt/nextcloud_backup/tools/toolbox.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit 2c506c2

Please sign in to comment.