From 23cd0705c581f3604fb3b728aeedc7801d3ed7cd Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 23 Jun 2022 17:19:28 +0200 Subject: [PATCH] feat: maximum file size bytes conversion --- src/lib/helpers/sizeConvertion.ts | 6 +++++ .../storage/bucket/[bucket]/settings.svelte | 23 ++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/lib/helpers/sizeConvertion.ts b/src/lib/helpers/sizeConvertion.ts index 702810a79..e62d7a9f0 100644 --- a/src/lib/helpers/sizeConvertion.ts +++ b/src/lib/helpers/sizeConvertion.ts @@ -9,3 +9,9 @@ export function bytesToSize(bytes: number, decimals = 1) { return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; } + +export function sizeToBytes(value: number, unit: string) { + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + const index = sizes.indexOf(unit); + return value * Math.pow(1024, index); +} diff --git a/src/routes/console/[project]/storage/bucket/[bucket]/settings.svelte b/src/routes/console/[project]/storage/bucket/[bucket]/settings.svelte index f5926626a..917b4cfb5 100644 --- a/src/routes/console/[project]/storage/bucket/[bucket]/settings.svelte +++ b/src/routes/console/[project]/storage/bucket/[bucket]/settings.svelte @@ -12,6 +12,7 @@ } from '$lib/elements/forms'; import { bucket } from './store'; import { toLocaleDateTime } from '$lib/helpers/date'; + import { sizeToBytes } from '$lib/helpers/sizeConvertion'; import { sdkForProject } from '$lib/stores/sdk'; import { addNotification } from '$lib/stores/notifications'; import Delete from './_deleteBucket.svelte'; @@ -29,11 +30,12 @@ let encryption = $bucket.response.encryption; let antivirus = $bucket.response.antivirus; let maxSize: number; + let byteUnit: 'Bytes' | 'KB' | 'MB' | 'GB' = 'Bytes'; let options = [ - { label: 'Bytes', value: 'b' }, - { label: 'Kilobytes', value: 'kb' }, - { label: 'Megabytes', value: 'mb' }, - { label: 'Gigabytes', value: 'gb' } + { label: 'Bytes', value: 'Bytes' }, + { label: 'Kilobytes', value: 'KB' }, + { label: 'Megabytes', value: 'MB' }, + { label: 'Gigabytes', value: 'GB' } ]; let extensions = $bucket.response.allowedFileExtensions; let isExtensionsDisabled = true; @@ -156,6 +158,8 @@ } } async function updateMaxSize() { + let size = sizeToBytes(maxSize, byteUnit); + console.log(size); try { await sdkForProject.storage.updateBucket( $bucket.response.$id, @@ -164,7 +168,7 @@ $bucket.response.$read, $bucket.response.$write, $bucket.response.enabled, - maxSize + size ); $bucket.response.maximumFileSize = maxSize; addNotification({ @@ -349,11 +353,8 @@ -

Session Length

-

- If you reduce the limit, users who are currently logged in will be logged out of the - application. -

+

Update Maximum File Size

+

Set the maximum file size allowed in the bucket.

    - +