web/ProcessingQueueItem: format file size to be readable

This commit is contained in:
wukko
2025-01-25 02:06:50 +06:00
parent 44a99bdb3a
commit 1e6b1cb201
2 changed files with 20 additions and 4 deletions

14
web/src/lib/util.ts Normal file
View File

@@ -0,0 +1,14 @@
export const formatFileSize = (size: number | undefined) => {
size ||= 0;
// gigabyte, megabyte, kilobyte, byte
const units = ['G', 'M', 'K', ''];
while (size >= 1024 && units.length > 1) {
size /= 1024;
units.pop();
}
const roundedSize = parseFloat(size.toFixed(2));
const unit = units[units.length - 1] + "B";
return `${roundedSize} ${unit}`;
}