From a3e7e8cc3193df75a37f98b9c82adbabb74450c4 Mon Sep 17 00:00:00 2001 From: Zack Pollard Date: Wed, 22 May 2024 10:25:55 +0100 Subject: [PATCH] refactor: deprecate /server-info and replace with /server-info/storage (#9645) --- .../server_info/server_disk_info.model.dart | 2 +- .../lib/providers/backup/backup.provider.dart | 12 +- .../backup/manual_upload.provider.dart | 2 +- mobile/lib/services/server_info.service.dart | 6 +- .../common/app_bar_dialog/app_bar_dialog.dart | 2 +- mobile/openapi/README.md | Bin 27063 -> 27273 bytes mobile/openapi/lib/api.dart | Bin 9665 -> 9700 bytes mobile/openapi/lib/api/deprecated_api.dart | Bin 0 -> 1893 bytes mobile/openapi/lib/api/server_info_api.dart | Bin 11619 -> 13099 bytes mobile/openapi/lib/api_client.dart | Bin 26051 -> 26057 bytes ....dart => server_storage_response_dto.dart} | Bin 4703 -> 4757 bytes open-api/immich-openapi-specs.json | 122 ++++++++++++------ open-api/typescript-sdk/src/fetch-client.ts | 15 ++- .../src/controllers/server-info.controller.ts | 14 +- server/src/dtos/server-info.dto.ts | 2 +- .../src/services/server-info.service.spec.ts | 14 +- server/src/services/server-info.service.ts | 6 +- web/src/lib/stores/server-info.store.ts | 4 +- web/src/lib/utils/auth.ts | 4 +- 19 files changed, 131 insertions(+), 74 deletions(-) create mode 100644 mobile/openapi/lib/api/deprecated_api.dart rename mobile/openapi/lib/model/{server_info_response_dto.dart => server_storage_response_dto.dart} (71%) diff --git a/mobile/lib/models/server_info/server_disk_info.model.dart b/mobile/lib/models/server_info/server_disk_info.model.dart index 95e94e369c..01ce49beec 100644 --- a/mobile/lib/models/server_info/server_disk_info.model.dart +++ b/mobile/lib/models/server_info/server_disk_info.model.dart @@ -32,7 +32,7 @@ class ServerDiskInfo { return 'ServerDiskInfo(diskAvailable: $diskAvailable, diskSize: $diskSize, diskUse: $diskUse, diskUsagePercentage: $diskUsagePercentage)'; } - ServerDiskInfo.fromDto(ServerInfoResponseDto dto) + ServerDiskInfo.fromDto(ServerStorageResponseDto dto) : diskAvailable = dto.diskAvailable, diskSize = dto.diskSize, diskUse = dto.diskUse, diff --git a/mobile/lib/providers/backup/backup.provider.dart b/mobile/lib/providers/backup/backup.provider.dart index ab869c2328..58027e3b94 100644 --- a/mobile/lib/providers/backup/backup.provider.dart +++ b/mobile/lib/providers/backup/backup.provider.dart @@ -374,7 +374,7 @@ class BackupNotifier extends StateNotifier { if (state.backupProgress != BackUpProgressEnum.inBackground) { await _getBackupAlbumsInfo(); - await updateServerInfo(); + await updateDiskInfo(); await _updateBackupAssetCount(); } else { log.warning("cannot get backup info - background backup is in progress!"); @@ -542,7 +542,7 @@ class BackupNotifier extends StateNotifier { _updatePersistentAlbumsSelection(); } - updateServerInfo(); + updateDiskInfo(); } void _onUploadProgress(int sent, int total) { @@ -579,13 +579,13 @@ class BackupNotifier extends StateNotifier { ); } - Future updateServerInfo() async { - final serverInfo = await _serverInfoService.getServerInfo(); + Future updateDiskInfo() async { + final diskInfo = await _serverInfoService.getDiskInfo(); // Update server info - if (serverInfo != null) { + if (diskInfo != null) { state = state.copyWith( - serverInfo: serverInfo, + serverInfo: diskInfo, ); } } diff --git a/mobile/lib/providers/backup/manual_upload.provider.dart b/mobile/lib/providers/backup/manual_upload.provider.dart index 1de7f7a788..b446711226 100644 --- a/mobile/lib/providers/backup/manual_upload.provider.dart +++ b/mobile/lib/providers/backup/manual_upload.provider.dart @@ -121,7 +121,7 @@ class ManualUploadNotifier extends StateNotifier { bool isDuplicated, ) { state = state.copyWith(successfulUploads: state.successfulUploads + 1); - _backupProvider.updateServerInfo(); + _backupProvider.updateDiskInfo(); } void _onAssetUploadError(ErrorUploadAsset errorAssetInfo) { diff --git a/mobile/lib/services/server_info.service.dart b/mobile/lib/services/server_info.service.dart index a2ce77c820..e2b7db2fce 100644 --- a/mobile/lib/services/server_info.service.dart +++ b/mobile/lib/services/server_info.service.dart @@ -18,14 +18,14 @@ class ServerInfoService { ServerInfoService(this._apiService); - Future getServerInfo() async { + Future getDiskInfo() async { try { - final dto = await _apiService.serverInfoApi.getServerInfo(); + final dto = await _apiService.serverInfoApi.getStorage(); if (dto != null) { return ServerDiskInfo.fromDto(dto); } } catch (e) { - debugPrint("Error [getServerInfo] ${e.toString()}"); + debugPrint("Error [getDiskInfo] ${e.toString()}"); } return null; } diff --git a/mobile/lib/widgets/common/app_bar_dialog/app_bar_dialog.dart b/mobile/lib/widgets/common/app_bar_dialog/app_bar_dialog.dart index 75d3966b97..fbcfd64713 100644 --- a/mobile/lib/widgets/common/app_bar_dialog/app_bar_dialog.dart +++ b/mobile/lib/widgets/common/app_bar_dialog/app_bar_dialog.dart @@ -31,7 +31,7 @@ class ImmichAppBarDialog extends HookConsumerWidget { useEffect( () { - ref.read(backupProvider.notifier).updateServerInfo(); + ref.read(backupProvider.notifier).updateDiskInfo(); ref.read(currentUserProvider.notifier).refresh(); return null; }, diff --git a/mobile/openapi/README.md b/mobile/openapi/README.md index 090182fc397e78b7d9c2e60d25f0c24e98ba16a8..605574260202200de446af74390dfc5486e3e4ba 100644 GIT binary patch delta 127 zcmdmfnX&UK;|32&&eVdU)a1mH)Rf5&^@Jz)>+y2AAcU6b8BX3LDYZFKvQ~_(B)=#z zJ$168o*az1P+yY07$Us+puVK`WV2||$e& E0NtrBUjP6A delta 50 zcmeCY%DDY9;|34O&1)s6iEUnG@JEZqGcPTF^2SIJj-s;EA~44xN^J6?=v|xV#JuGN E045X_ng9R* diff --git a/mobile/openapi/lib/api.dart b/mobile/openapi/lib/api.dart index 8cd0f4365ca15e6d138cc40441ab0b375bb6274d..be7c4a936e782ce5e2c8d21c7bf87e0f051cab79 100644 GIT binary patch delta 43 zcmX@;{lt62erC?pf}+&q#FEsM$qFoDoA)uNi%t%d>|if0$uCMwPu;vxQh)~lew`3I delta 30 mcmaFjeb9Tue&)^hnbSmBGV{{%CkqNGPPUWm-~31N1vdc8XAF4& diff --git a/mobile/openapi/lib/api/deprecated_api.dart b/mobile/openapi/lib/api/deprecated_api.dart new file mode 100644 index 0000000000000000000000000000000000000000..117735015d695bb2136b54ef9afa6608dddfa7cc GIT binary patch literal 1893 zcmb7EZBN@s5dQ98G37&(NUj4_b*g9~my$q{dW3^i)d?YYiO2EYIlJ!em^4NF_s;Ix zNvJ}l`w(Y$c3z)(X8Qf8--qGn>EzYf_+orDoQ_9udj4q~!)O8*lPUZ)8J(a0^Mci! z=AW4`bo4qocpJH^oGWcG&9zB$S>hqosE5vTq?DY(0N5}bZ+mdKxxvxa zc`$$sb5WPHHsoLcxm2QrwQOVIU;7OCw2&4m!&w?y!BSXu)aC|K!TmvUu>VK0&(2sq zeBnY9H^-YYqJ_@DAk{`$paS9Jbb1LlS7<8+6K@kXI<5H`-?y@3m?K@Ixkq!Za{Wb8 z@sX%<=WY*#U8$J|#l>t$amYzx&M^B9r5Q4iMv&wX?7ywF5>zlSrqj3H`zy&VJHFUm zzC1kKznLh5m&x6~IAhE!ZRvx~R*hwV@mq~%b?I1SImY|H*Vp5l+jm<@6euz@8^vof zQq5xs|HluH+se%K#cx%;V_!7zmzWaMRfRr-#-WSunhi}CHeF7ny4U~V@bbLt-vJyz zadYmRji;UVvQ=CwYC&l4+jX_FP5P~5JIO@a@uFg04M5dp$@G2l>c=qH^&BRTu8RLj z%7$5iOxL81m}5(`5$VA%RQrWqp|Pf+svD`Lkn}rthTh2>x~)~h3xjHVqBDf!BXC5% z_LAgIWLLa{&{D6VGw^^Iy>t^f{yxLX@pqS_xJktEoc%f~epnIOwQkP?<{)!@=PCJ8 zpaQ`RSnzB@VE=k5m4-WZ0ZSe z(3vcaB&IXVq>bULTi}P>RUT#f$^qC-C{ZZb`>gPL#RG*Ipvs)JRJ@t@TGyvcenD#_ zVCjk=v-19Rn+tnF&m!vwDJ1r!1Fksc8n2~5x0f%u^ss)myYu2nca%N}^R#JB*kTR# x>%E&~$aqRo${#p%yQv#k@_ch*=sZWrPV5#OJog;vCbuj<{ literal 0 HcmV?d00001 diff --git a/mobile/openapi/lib/api/server_info_api.dart b/mobile/openapi/lib/api/server_info_api.dart index db72dd370d2ea66f6acea14c8a213c168a6db910..6e55c62759041511ef8c745f3a51be8ce69c01f7 100644 GIT binary patch delta 321 zcmaDHwK{FXB%bh)jLc$%f};F_)S{9~h4RE=g_P8SqSWNXlGGH1%shoMLp?(SGd%+? z1qFS5eF&-GmtT@ufn9U+4<11#XP_>K zO5!YWD+L;qY7?AVRF+y4T#{dun4UU$u88<%L;hkWc9_6E83{Q1u1xr5X(35&_F|}N zLk;W64eTszQ0_$b1enz3yFz;zWx-|!r4|?D=M|^Al;qpnDWs>Cz>H30(SqvSte{|n L)ymCxW!eM)e*|v9 delta 66 zcmZ3T_Bd+8B%aB)#g!)a%Gz({Bz4?!lz5oCqs1|kr diff --git a/mobile/openapi/lib/api_client.dart b/mobile/openapi/lib/api_client.dart index 2bebf46b1c4913652437e5c3aae9c382e35a4e8e..3e2f2c15c63bd35ec530b3a4f4645fa7b11133f4 100644 GIT binary patch delta 48 zcmX?nn(^dm#tj!;HtV}8F|q}hy#tj!;SUmI6@+UhwDY6umr4~)L^)%Rg#zmcRbGTcPJOC^04v7E& diff --git a/mobile/openapi/lib/model/server_info_response_dto.dart b/mobile/openapi/lib/model/server_storage_response_dto.dart similarity index 71% rename from mobile/openapi/lib/model/server_info_response_dto.dart rename to mobile/openapi/lib/model/server_storage_response_dto.dart index 295e0f7e6af32d1e0a0ddce66cfa13ae7f4d7316..ab0f169e4b827a74d47982b31b5fa8bc81f09f1c 100644 GIT binary patch delta 232 zcmcbwGF5ehE+czzNq$jcdg^3DMol<7j!_=Q-rUIe7OrS>5pyLIT;@INVmN2=G>)Y( ziOKeytuXfH6P)S@MW4CjU=ou("/server-info", { ...opts })); @@ -2293,6 +2296,14 @@ export function getServerStatistics(opts?: Oazapfts.RequestOpts) { ...opts })); } +export function getStorage(opts?: Oazapfts.RequestOpts) { + return oazapfts.ok(oazapfts.fetchJson<{ + status: 200; + data: ServerStorageResponseDto; + }>("/server-info/storage", { + ...opts + })); +} export function getTheme(opts?: Oazapfts.RequestOpts) { return oazapfts.ok(oazapfts.fetchJson<{ status: 200; diff --git a/server/src/controllers/server-info.controller.ts b/server/src/controllers/server-info.controller.ts index 960acfe3fd..308778dbb5 100644 --- a/server/src/controllers/server-info.controller.ts +++ b/server/src/controllers/server-info.controller.ts @@ -1,12 +1,13 @@ import { Controller, Get } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; +import { EndpointLifecycle } from 'src/decorators'; import { ServerConfigDto, ServerFeaturesDto, - ServerInfoResponseDto, ServerMediaTypesResponseDto, ServerPingResponse, ServerStatsResponseDto, + ServerStorageResponseDto, ServerThemeDto, ServerVersionResponseDto, } from 'src/dtos/server-info.dto'; @@ -23,9 +24,16 @@ export class ServerInfoController { ) {} @Get() + @EndpointLifecycle({ deprecatedAt: 'v1.106.0' }) @Authenticated() - getServerInfo(): Promise { - return this.service.getInfo(); + getServerInfo(): Promise { + return this.service.getStorage(); + } + + @Get('storage') + @Authenticated() + getStorage(): Promise { + return this.service.getStorage(); } @Get('ping') diff --git a/server/src/dtos/server-info.dto.ts b/server/src/dtos/server-info.dto.ts index 1e91332c0d..6afe8534c7 100644 --- a/server/src/dtos/server-info.dto.ts +++ b/server/src/dtos/server-info.dto.ts @@ -7,7 +7,7 @@ export class ServerPingResponse { res!: string; } -export class ServerInfoResponseDto { +export class ServerStorageResponseDto { diskSize!: string; diskUse!: string; diskAvailable!: string; diff --git a/server/src/services/server-info.service.spec.ts b/server/src/services/server-info.service.spec.ts index 41f2e95e22..57beb165db 100644 --- a/server/src/services/server-info.service.spec.ts +++ b/server/src/services/server-info.service.spec.ts @@ -29,11 +29,11 @@ describe(ServerInfoService.name, () => { expect(sut).toBeDefined(); }); - describe('getInfo', () => { + describe('getStorage', () => { it('should return the disk space as B', async () => { storageMock.checkDiskUsage.mockResolvedValue({ free: 200, available: 300, total: 500 }); - await expect(sut.getInfo()).resolves.toEqual({ + await expect(sut.getStorage()).resolves.toEqual({ diskAvailable: '300 B', diskAvailableRaw: 300, diskSize: '500 B', @@ -49,7 +49,7 @@ describe(ServerInfoService.name, () => { it('should return the disk space as KiB', async () => { storageMock.checkDiskUsage.mockResolvedValue({ free: 200_000, available: 300_000, total: 500_000 }); - await expect(sut.getInfo()).resolves.toEqual({ + await expect(sut.getStorage()).resolves.toEqual({ diskAvailable: '293.0 KiB', diskAvailableRaw: 300_000, diskSize: '488.3 KiB', @@ -65,7 +65,7 @@ describe(ServerInfoService.name, () => { it('should return the disk space as MiB', async () => { storageMock.checkDiskUsage.mockResolvedValue({ free: 200_000_000, available: 300_000_000, total: 500_000_000 }); - await expect(sut.getInfo()).resolves.toEqual({ + await expect(sut.getStorage()).resolves.toEqual({ diskAvailable: '286.1 MiB', diskAvailableRaw: 300_000_000, diskSize: '476.8 MiB', @@ -85,7 +85,7 @@ describe(ServerInfoService.name, () => { total: 500_000_000_000, }); - await expect(sut.getInfo()).resolves.toEqual({ + await expect(sut.getStorage()).resolves.toEqual({ diskAvailable: '279.4 GiB', diskAvailableRaw: 300_000_000_000, diskSize: '465.7 GiB', @@ -105,7 +105,7 @@ describe(ServerInfoService.name, () => { total: 500_000_000_000_000, }); - await expect(sut.getInfo()).resolves.toEqual({ + await expect(sut.getStorage()).resolves.toEqual({ diskAvailable: '272.8 TiB', diskAvailableRaw: 300_000_000_000_000, diskSize: '454.7 TiB', @@ -125,7 +125,7 @@ describe(ServerInfoService.name, () => { total: 500_000_000_000_000_000, }); - await expect(sut.getInfo()).resolves.toEqual({ + await expect(sut.getStorage()).resolves.toEqual({ diskAvailable: '266.5 PiB', diskAvailableRaw: 300_000_000_000_000_000, diskSize: '444.1 PiB', diff --git a/server/src/services/server-info.service.ts b/server/src/services/server-info.service.ts index 9e27e9d7ac..89e095ba5d 100644 --- a/server/src/services/server-info.service.ts +++ b/server/src/services/server-info.service.ts @@ -4,10 +4,10 @@ import { SystemConfigCore } from 'src/cores/system-config.core'; import { ServerConfigDto, ServerFeaturesDto, - ServerInfoResponseDto, ServerMediaTypesResponseDto, ServerPingResponse, ServerStatsResponseDto, + ServerStorageResponseDto, UsageByUserDto, } from 'src/dtos/server-info.dto'; import { SystemMetadataKey } from 'src/entities/system-metadata.entity'; @@ -42,13 +42,13 @@ export class ServerInfoService { } } - async getInfo(): Promise { + async getStorage(): Promise { const libraryBase = StorageCore.getBaseFolder(StorageFolder.LIBRARY); const diskInfo = await this.storageRepository.checkDiskUsage(libraryBase); const usagePercentage = (((diskInfo.total - diskInfo.free) / diskInfo.total) * 100).toFixed(2); - const serverInfo = new ServerInfoResponseDto(); + const serverInfo = new ServerStorageResponseDto(); serverInfo.diskAvailable = asHumanReadable(diskInfo.available); serverInfo.diskSize = asHumanReadable(diskInfo.total); serverInfo.diskUse = asHumanReadable(diskInfo.total - diskInfo.free); diff --git a/web/src/lib/stores/server-info.store.ts b/web/src/lib/stores/server-info.store.ts index 817bbeca4a..360b2c5630 100644 --- a/web/src/lib/stores/server-info.store.ts +++ b/web/src/lib/stores/server-info.store.ts @@ -1,4 +1,4 @@ -import type { ServerInfoResponseDto } from '@immich/sdk'; +import type { ServerStorageResponseDto } from '@immich/sdk'; import { writable } from 'svelte/store'; -export const serverInfo = writable(); +export const serverInfo = writable(); diff --git a/web/src/lib/utils/auth.ts b/web/src/lib/utils/auth.ts index dc7bb53db1..1fbc158f74 100644 --- a/web/src/lib/utils/auth.ts +++ b/web/src/lib/utils/auth.ts @@ -1,7 +1,7 @@ import { browser } from '$app/environment'; import { serverInfo } from '$lib/stores/server-info.store'; import { user } from '$lib/stores/user.store'; -import { getMyUserInfo, getServerInfo } from '@immich/sdk'; +import { getMyUserInfo, getStorage } from '@immich/sdk'; import { redirect } from '@sveltejs/kit'; import { get } from 'svelte/store'; import { AppRoute } from '../constants'; @@ -58,7 +58,7 @@ export const authenticate = async (options?: AuthOptions) => { export const requestServerInfo = async () => { if (get(user)) { - const data = await getServerInfo(); + const data = await getStorage(); serverInfo.set(data); } };