status-box.svelte 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <script lang="ts">
  2. import { onDestroy, onMount } from 'svelte';
  3. import Cloud from 'svelte-material-icons/Cloud.svelte';
  4. import Dns from 'svelte-material-icons/Dns.svelte';
  5. import LoadingSpinner from './loading-spinner.svelte';
  6. import { api, ServerInfoResponseDto } from '@api';
  7. let isServerOk = true;
  8. let serverVersion = '';
  9. let serverInfo: ServerInfoResponseDto;
  10. onMount(async () => {
  11. try {
  12. const { data: version } = await api.serverInfoApi.getServerVersion();
  13. serverVersion = `v${version.major}.${version.minor}.${version.patch}`;
  14. const { data: serverInfoRes } = await api.serverInfoApi.getServerInfo();
  15. serverInfo = serverInfoRes;
  16. getStorageUsagePercentage();
  17. } catch (e) {
  18. console.log('Error [StatusBox] [onMount]');
  19. isServerOk = false;
  20. }
  21. });
  22. const pingServerInterval = setInterval(async () => {
  23. try {
  24. const { data: pingReponse } = await api.serverInfoApi.pingServer();
  25. if (pingReponse.res === 'pong') isServerOk = true;
  26. else isServerOk = false;
  27. const { data: serverInfoRes } = await api.serverInfoApi.getServerInfo();
  28. serverInfo = serverInfoRes;
  29. } catch (e) {
  30. console.log('Error [StatusBox] [pingServerInterval]');
  31. isServerOk = false;
  32. }
  33. }, 10000);
  34. onDestroy(() => clearInterval(pingServerInterval));
  35. const getStorageUsagePercentage = () => {
  36. return Math.round((serverInfo?.diskUseRaw / serverInfo?.diskSizeRaw) * 100);
  37. };
  38. </script>
  39. <div>
  40. <div class="storage-status grid grid-cols-[64px_auto]">
  41. <div class="pl-5 pr-6 text-immich-primary">
  42. <Cloud size={'24'} />
  43. </div>
  44. <div>
  45. <p class="text-sm font-medium text-immich-primary">Storage</p>
  46. {#if serverInfo}
  47. <div class="w-full bg-gray-200 rounded-full h-[7px] dark:bg-gray-700 my-2">
  48. <!-- style={`width: ${$downloadAssets[fileName]}%`} -->
  49. <div
  50. class="bg-immich-primary h-[7px] rounded-full"
  51. style={`width: ${getStorageUsagePercentage()}%`}
  52. />
  53. </div>
  54. <p class="text-xs">{serverInfo?.diskUse} of {serverInfo?.diskSize} used</p>
  55. {:else}
  56. <div class="mt-2">
  57. <LoadingSpinner />
  58. </div>
  59. {/if}
  60. </div>
  61. </div>
  62. <div>
  63. <hr class="ml-5 my-4" />
  64. </div>
  65. <div class="server-status grid grid-cols-[64px_auto]">
  66. <div class="pl-5 pr-6 text-immich-primary">
  67. <Dns size={'24'} />
  68. </div>
  69. <div class="text-xs">
  70. <p class="text-sm font-medium text-immich-primary">Server</p>
  71. <div class="flex justify-items-center justify-between mt-2">
  72. <p>Status</p>
  73. {#if isServerOk}
  74. <p class="font-medium text-immich-primary">Online</p>
  75. {:else}
  76. <p class="font-medium text-red-500">Offline</p>
  77. {/if}
  78. </div>
  79. <div class="flex justify-items-center justify-between mt-2">
  80. <p>Version</p>
  81. <p class="font-medium text-immich-primary">{serverVersion}</p>
  82. </div>
  83. </div>
  84. </div>
  85. <!-- <div>
  86. <hr class="ml-5 my-4" />
  87. </div>
  88. <button class="text-xs ml-5 underline hover:cursor-pointer text-immich-primary" on:click={() => goto('/changelog')}
  89. >Changelog</button
  90. > -->
  91. </div>