adds width and height to uploads that match proper mime type, continues build to FileDetails
This commit is contained in:
13
src/uploads/formatFilesize.js
Normal file
13
src/uploads/formatFilesize.js
Normal file
@@ -0,0 +1,13 @@
|
||||
function formatBytes(bytes, decimals = 0) {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
|
||||
const k = 1024;
|
||||
const dm = decimals < 0 ? 0 : decimals;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
|
||||
return `${parseFloat((bytes / (k ** i)).toFixed(dm))} ${sizes[i]}`;
|
||||
}
|
||||
|
||||
module.exports = formatBytes;
|
||||
Reference in New Issue
Block a user