status-box.svelte 3.1 KB

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