refactor(web): byte unit utils (#10332)

refactor byte unit utils
This commit is contained in:
Daniel Dietzler 2024-06-14 19:27:46 +02:00 committed by GitHub
parent b4b654b53f
commit c896fe393f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 99 additions and 87 deletions

View file

@ -2,7 +2,6 @@
import FullScreenModal from '$lib/components/shared-components/full-screen-modal.svelte';
import { AppRoute } from '$lib/constants';
import { serverInfo } from '$lib/stores/server-info.store';
import { convertFromBytes, convertToBytes } from '$lib/utils/byte-converter';
import { handleError } from '$lib/utils/handle-error';
import { updateUserAdmin, type UserAdminResponseDto } from '@immich/sdk';
import { mdiAccountEditOutline } from '@mdi/js';
@ -10,6 +9,7 @@
import Button from '../elements/buttons/button.svelte';
import { dialogController } from '$lib/components/shared-components/dialog/dialog';
import { t } from 'svelte-i18n';
import { ByteUnit, convertFromBytes, convertToBytes } from '$lib/utils/byte-units';
export let user: UserAdminResponseDto;
export let canResetPassword = true;
@ -18,14 +18,14 @@
let error: string;
let success: string;
let quotaSize = user.quotaSizeInBytes ? convertFromBytes(user.quotaSizeInBytes, 'GiB') : null;
let quotaSize = user.quotaSizeInBytes ? convertFromBytes(user.quotaSizeInBytes, ByteUnit.GiB) : null;
const previousQutoa = user.quotaSizeInBytes;
$: quotaSizeWarning =
previousQutoa !== convertToBytes(Number(quotaSize), 'GiB') &&
previousQutoa !== convertToBytes(Number(quotaSize), ByteUnit.GiB) &&
!!quotaSize &&
convertToBytes(Number(quotaSize), 'GiB') > $serverInfo.diskSizeRaw;
convertToBytes(Number(quotaSize), ByteUnit.GiB) > $serverInfo.diskSizeRaw;
const dispatch = createEventDispatcher<{
close: void;
@ -42,7 +42,7 @@
email,
name,
storageLabel: storageLabel || '',
quotaSizeInBytes: quotaSize ? convertToBytes(Number(quotaSize), 'GiB') : null,
quotaSizeInBytes: quotaSize ? convertToBytes(Number(quotaSize), ByteUnit.GiB) : null,
},
});