2024-07-18 10:56:27 -05:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { locale } from '$lib/stores/preferences.store';
|
|
|
|
|
import { user } from '$lib/stores/user.store';
|
|
|
|
|
import { requestServerInfo } from '$lib/utils/auth';
|
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import { t } from 'svelte-i18n';
|
2024-12-16 15:45:01 +01:00
|
|
|
import { getByteUnitString } from '$lib/utils/byte-units';
|
2024-07-18 10:56:27 -05:00
|
|
|
import LoadingSpinner from '../loading-spinner.svelte';
|
2024-12-16 15:45:01 +01:00
|
|
|
import { userInteraction } from '$lib/stores/user.svelte';
|
2024-07-18 10:56:27 -05:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let usageClasses = $state('');
|
2024-07-18 10:56:27 -05:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let hasQuota = $derived($user?.quotaSizeInBytes !== null);
|
2024-12-16 15:45:01 +01:00
|
|
|
let availableBytes = $derived((hasQuota ? $user?.quotaSizeInBytes : userInteraction.serverInfo?.diskSizeRaw) || 0);
|
|
|
|
|
let usedBytes = $derived((hasQuota ? $user?.quotaUsageInBytes : userInteraction.serverInfo?.diskUseRaw) || 0);
|
2024-11-14 08:43:25 -06:00
|
|
|
let usedPercentage = $derived(Math.min(Math.round((usedBytes / availableBytes) * 100), 100));
|
2024-07-18 10:56:27 -05:00
|
|
|
|
|
|
|
|
const onUpdate = () => {
|
|
|
|
|
usageClasses = getUsageClass();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getUsageClass = () => {
|
|
|
|
|
if (usedPercentage >= 95) {
|
|
|
|
|
return 'bg-red-500';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (usedPercentage > 80) {
|
|
|
|
|
return 'bg-yellow-500';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 'bg-immich-primary dark:bg-immich-dark-primary';
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
$effect(() => {
|
|
|
|
|
if ($user) {
|
|
|
|
|
onUpdate();
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-07-18 10:56:27 -05:00
|
|
|
|
|
|
|
|
onMount(async () => {
|
2024-12-16 15:45:01 +01:00
|
|
|
if (userInteraction.serverInfo && $user) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-07-18 10:56:27 -05:00
|
|
|
await requestServerInfo();
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div
|
2025-04-01 22:12:04 -04:00
|
|
|
class="storage-status p-4 bg-gray-100 dark:bg-immich-dark-primary/10 ml-4 rounded-lg text-sm min-w-52"
|
2024-07-18 10:56:27 -05:00
|
|
|
title={$t('storage_usage', {
|
|
|
|
|
values: {
|
|
|
|
|
used: getByteUnitString(usedBytes, $locale, 3),
|
|
|
|
|
available: getByteUnitString(availableBytes, $locale, 3),
|
|
|
|
|
},
|
|
|
|
|
})}
|
|
|
|
|
>
|
2025-04-01 22:12:04 -04:00
|
|
|
<p class="font-medium text-immich-dark-gray dark:text-white mb-2">{$t('storage')}</p>
|
2024-07-18 10:56:27 -05:00
|
|
|
|
2025-04-01 22:12:04 -04:00
|
|
|
{#if userInteraction.serverInfo}
|
|
|
|
|
<p class="text-gray-500 dark:text-gray-300">
|
|
|
|
|
{$t('storage_usage', {
|
|
|
|
|
values: {
|
|
|
|
|
used: getByteUnitString(usedBytes, $locale),
|
|
|
|
|
available: getByteUnitString(availableBytes, $locale),
|
|
|
|
|
},
|
|
|
|
|
})}
|
|
|
|
|
</p>
|
2024-07-18 10:56:27 -05:00
|
|
|
|
2025-04-01 22:12:04 -04:00
|
|
|
<div class="mt-4 h-[7px] w-full rounded-full bg-gray-200 dark:bg-gray-700">
|
|
|
|
|
<div class="h-[7px] rounded-full {usageClasses}" style="width: {usedPercentage}%"></div>
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="mt-2">
|
|
|
|
|
<LoadingSpinner />
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2024-07-18 10:56:27 -05:00
|
|
|
</div>
|