mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
file api added, bugs in file view fixed
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
export function get_uuid(): string {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
|
||||
export function get_file_size_display_string(size: number, toFixed: number|null = null): string {
|
||||
if (size === 0) return "0 B";
|
||||
|
||||
const k = 1024;
|
||||
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
||||
|
||||
const i = Math.floor(Math.log(size) / Math.log(k));
|
||||
const value = size / Math.pow(k, i);
|
||||
|
||||
const size_string = `${value.toFixed(toFixed !== null ? toFixed : Math.max(0, 2 - Math.floor(Math.log10(value))))} ${sizes[i]}`;
|
||||
|
||||
return size_string.replace('.', ',');
|
||||
}
|
||||
Reference in New Issue
Block a user