feat(frontend): add formatBytes util for human-readable file sizes

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 15:53:03 +02:00
co-authored by Claude Sonnet 5
parent 3cff496a85
commit f5958586b7
+10
View File
@@ -0,0 +1,10 @@
const UNITS = ['B', 'KB', 'MB', 'GB'];
export function formatBytes(bytes) {
if (!bytes || bytes <= 0) return '0 B';
const exponent = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), UNITS.length - 1);
const value = bytes / 1024 ** exponent;
const rounded = Math.round(value * 10) / 10;
const formatted = Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1);
return `${formatted} ${UNITS[exponent]}`;
}