Added more sizes

This commit is contained in:
ArabCoders 2024-01-03 00:32:28 +03:00
parent 44d2bd081c
commit f15e380645

View file

@ -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, {