diff --git a/src/lib/helpers/sizeConvertion.ts b/src/lib/helpers/sizeConvertion.ts new file mode 100644 index 000000000..702810a79 --- /dev/null +++ b/src/lib/helpers/sizeConvertion.ts @@ -0,0 +1,11 @@ +export function bytesToSize(bytes: number, decimals = 1) { + 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 / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/index.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/index.svelte index 2498a1e7d..c9b89c353 100644 --- a/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/index.svelte +++ b/src/routes/console/[project]/storage/bucket/[bucket]/file/[file]/index.svelte @@ -7,6 +7,7 @@ import { toLocaleDate } from '$lib/helpers/date'; import { sdkForProject } from '$lib/stores/sdk'; import { addNotification } from '$lib/stores/notifications'; + import { bytesToSize } from '$lib/helpers/sizeConvertion'; import Delete from './_deleteFile.svelte'; let showDelete = false; @@ -99,7 +100,7 @@
MIME Type: {$file.response.mimeType}
-Size: {$file.response.sizeOriginal}
+Size: {bytesToSize($file.response.sizeOriginal)}
Created: {toLocaleDate($file.response.dateCreated)}
Last Updated (to implement): {toLocaleDate($file.response.dateCreated)}