diff --git a/frontend/src/main.js b/frontend/src/main.js index aff8d528..660d8b1b 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -32,15 +32,15 @@ app.config.globalProperties.makeDownload = (config, item, base = 'download') => return config.app.url_host + config.app.url_prefix + baseDir + encodeURIComponent(item.filename); } app.config.globalProperties.formatBytes = (bytes, decimals = 2) => { - if (bytes === 0) return '0 Bytes'; + if (!+bytes) return '0 Bytes' - const k = 1024; - const dm = decimals < 0 ? 0 : decimals; - const sizes = ['Bytes', 'KB', 'MB']; + const k = 1024 + const dm = decimals < 0 ? 0 : decimals + const sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] - const i = Math.floor(Math.log(bytes) / Math.log(k)); + const i = Math.floor(Math.log(bytes) / Math.log(k)) - return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; + return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}` } app.use(Toast, {