From d8631a00bb3fd99eab3ba78943bb0514d38f731d Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Wed, 14 Feb 2024 08:09:49 -0500 Subject: [PATCH] refactor(web) open api client (#7103) * refactor: person api * refactor: shared link and others --- web/src/api/api.ts | 122 +----------------- web/src/api/utils.ts | 2 +- .../admin-page/jobs/job-tile.svelte | 11 +- .../admin-page/jobs/jobs-panel.svelte | 27 ++-- .../server-stats/server-stats-panel.svelte | 10 +- .../admin-page/settings/admin-settings.ts | 2 +- .../settings/ffmpeg/ffmpeg-settings.svelte | 27 ++-- .../settings/job-settings/job-settings.svelte | 8 +- .../library-settings/library-settings.svelte | 2 +- .../logging-settings/logging-settings.svelte | 3 +- .../machine-learning-settings.svelte | 2 +- .../settings/map-settings/map-settings.svelte | 2 +- .../new-version-check-settings.svelte | 2 +- .../settings/oauth/oauth-settings.svelte | 2 +- .../password-login-settings.svelte | 2 +- .../settings/server/server-settings.svelte | 6 +- .../supported-datetime-panel.svelte | 2 +- .../settings/theme/theme-settings.svelte | 2 +- .../thumbnail/thumbnail-settings.svelte | 3 +- .../trash-settings/trash-settings.svelte | 2 +- .../components/album-page/album-card.svelte | 3 +- .../lib/components/album-page/album-card.ts | 2 +- .../album-page/share-info-modal.svelte | 2 +- .../album-page/user-selection-modal.svelte | 12 +- .../asset-viewer/activity-viewer.svelte | 17 +-- .../asset-viewer/album-list-item.svelte | 5 +- .../asset-viewer/asset-viewer-nav-bar.svelte | 11 +- .../asset-viewer/asset-viewer.svelte | 22 ++-- .../asset-viewer/detail-panel.svelte | 75 +++++------ .../asset-viewer/panorama-viewer.svelte | 3 +- .../asset-viewer/photo-viewer.svelte | 23 ++-- .../asset-viewer/video-viewer.svelte | 13 +- .../assets/thumbnail/thumbnail.svelte | 25 ++-- .../faces-page/assign-face-side-panel.svelte | 26 ++-- .../faces-page/face-thumbnail.svelte | 13 +- .../faces-page/merge-face-selector.svelte | 31 ++--- .../faces-page/merge-suggestion-modal.svelte | 13 +- .../components/faces-page/people-card.svelte | 13 +- .../components/faces-page/people-list.svelte | 12 +- .../faces-page/person-side-panel.svelte | 33 ++--- .../faces-page/unmerge-face-selector.svelte | 44 +++---- .../memory-page/memory-viewer.svelte | 32 ++--- .../photos-page/actions/archive-action.svelte | 8 +- .../actions/asset-job-actions.svelte | 10 +- .../actions/change-date-action.svelte | 10 +- .../actions/change-location-action.svelte | 16 +-- .../actions/favorite-action.svelte | 10 +- .../actions/remove-from-shared-link.svelte | 16 ++- .../photos-page/actions/stack-action.svelte | 8 +- .../components/photos-page/memory-lane.svelte | 21 ++- .../individual-shared-viewer.svelte | 20 +-- .../create-shared-link-modal.svelte | 17 +-- .../shared-components/map/map.svelte | 6 +- .../navigation-bar/account-info-panel.svelte | 5 +- .../search-bar/search-filter-box.svelte | 24 ++-- .../side-bar/side-bar.svelte | 9 +- .../shared-components/user-avatar.svelte | 5 +- .../sharedlinks-page/shared-link-card.svelte | 22 ++-- web/src/lib/stores/asset-viewing.store.ts | 6 +- web/src/lib/stores/assets.store.ts | 18 +-- web/src/lib/utils.ts | 90 +++++++++++++ web/src/lib/utils/actions.ts | 4 +- web/src/lib/utils/asset-utils.ts | 11 +- web/src/lib/utils/file-uploader.ts | 3 +- web/src/routes/(user)/explore/+page.svelte | 5 +- web/src/routes/(user)/explore/+page.ts | 6 +- web/src/routes/(user)/map/+page.svelte | 10 +- web/src/routes/(user)/people/+page.svelte | 76 +++++------ web/src/routes/(user)/people/+page.ts | 4 +- .../(user)/people/[personId]/+page.svelte | 62 ++++----- .../routes/(user)/people/[personId]/+page.ts | 8 +- web/src/routes/(user)/places/+page.ts | 4 +- web/src/routes/(user)/search/+page.svelte | 13 +- web/src/routes/(user)/search/+page.ts | 12 +- .../routes/(user)/share/[key]/+page.svelte | 12 +- web/src/routes/(user)/share/[key]/+page.ts | 13 +- .../share/[key]/photos/[assetId]/+page.ts | 4 +- .../(user)/sharing/sharedlinks/+page.svelte | 22 ++-- web/src/routes/+layout.svelte | 30 ++--- web/src/routes/admin/jobs-status/+page.svelte | 3 +- web/src/test-data/factories/album-factory.ts | 2 +- 81 files changed, 638 insertions(+), 656 deletions(-) diff --git a/web/src/api/api.ts b/web/src/api/api.ts index c11ac66534..53340cb455 100644 --- a/web/src/api/api.ts +++ b/web/src/api/api.ts @@ -1,135 +1,15 @@ -import { - AssetApi, - AssetApiFp, - AssetJobName, - DownloadApi, - JobName, - PersonApi, - SearchApi, - SharedLinkApi, - UserApiFp, - base, - common, - configuration, -} from '@immich/sdk/axios'; -import type { ApiParams as ApiParameters } from './types'; +import { AssetApi, DownloadApi, configuration } from '@immich/sdk/axios'; class ImmichApi { public downloadApi: DownloadApi; public assetApi: AssetApi; - public searchApi: SearchApi; - public sharedLinkApi: SharedLinkApi; - public personApi: PersonApi; private config: configuration.Configuration; - private key?: string; - - get isSharedLink() { - return !!this.key; - } constructor(parameters: configuration.ConfigurationParameters) { this.config = new configuration.Configuration(parameters); - this.downloadApi = new DownloadApi(this.config); this.assetApi = new AssetApi(this.config); - this.searchApi = new SearchApi(this.config); - this.sharedLinkApi = new SharedLinkApi(this.config); - this.personApi = new PersonApi(this.config); - } - - private createUrl(path: string, parameters?: Record) { - const searchParameters = new URLSearchParams(); - for (const key in parameters) { - const value = parameters[key]; - if (value !== undefined && value !== null) { - searchParameters.set(key, value.toString()); - } - } - - const url = new URL(path, common.DUMMY_BASE_URL); - url.search = searchParameters.toString(); - - return (this.config.basePath || base.BASE_PATH) + common.toPathString(url); - } - - public setKey(key: string) { - this.key = key; - } - - public getKey(): string | undefined { - return this.key; - } - - public setAccessToken(accessToken: string) { - this.config.accessToken = accessToken; - } - - public removeAccessToken() { - this.config.accessToken = undefined; - } - - public setBaseUrl(baseUrl: string) { - this.config.basePath = baseUrl; - } - - public getAssetFileUrl(...[assetId, isThumb, isWeb]: ApiParameters) { - const path = `/asset/file/${assetId}`; - return this.createUrl(path, { isThumb, isWeb, key: this.getKey() }); - } - - public getAssetThumbnailUrl(...[assetId, format]: ApiParameters) { - const path = `/asset/thumbnail/${assetId}`; - return this.createUrl(path, { format, key: this.getKey() }); - } - - public getProfileImageUrl(...[userId]: ApiParameters) { - const path = `/user/profile-image/${userId}`; - return this.createUrl(path); - } - - public getPeopleThumbnailUrl(personId: string) { - const path = `/person/${personId}/thumbnail`; - return this.createUrl(path); - } - - public getJobName(jobName: JobName) { - const names: Record = { - [JobName.ThumbnailGeneration]: 'Generate Thumbnails', - [JobName.MetadataExtraction]: 'Extract Metadata', - [JobName.Sidecar]: 'Sidecar Metadata', - [JobName.SmartSearch]: 'Smart Search', - [JobName.FaceDetection]: 'Face Detection', - [JobName.FacialRecognition]: 'Facial Recognition', - [JobName.VideoConversion]: 'Transcode Videos', - [JobName.StorageTemplateMigration]: 'Storage Template Migration', - [JobName.Migration]: 'Migration', - [JobName.BackgroundTask]: 'Background Tasks', - [JobName.Search]: 'Search', - [JobName.Library]: 'Library', - }; - - return names[jobName]; - } - - public getAssetJobName(job: AssetJobName) { - const names: Record = { - [AssetJobName.RefreshMetadata]: 'Refresh metadata', - [AssetJobName.RegenerateThumbnail]: 'Refresh thumbnails', - [AssetJobName.TranscodeVideo]: 'Refresh encoded videos', - }; - - return names[job]; - } - - public getAssetJobMessage(job: AssetJobName) { - const messages: Record = { - [AssetJobName.RefreshMetadata]: 'Refreshing metadata', - [AssetJobName.RegenerateThumbnail]: `Regenerating thumbnails`, - [AssetJobName.TranscodeVideo]: `Refreshing encoded video`, - }; - - return messages[job]; } } diff --git a/web/src/api/utils.ts b/web/src/api/utils.ts index 0367e7905a..decfefc560 100644 --- a/web/src/api/utils.ts +++ b/web/src/api/utils.ts @@ -1,5 +1,5 @@ import { finishOAuth, linkOAuthAccount, startOAuth, unlinkOAuthAccount } from '@immich/sdk'; -import type { UserResponseDto } from '@immich/sdk/axios'; +import { type UserResponseDto } from '@immich/sdk/axios'; import type { AxiosError } from 'axios'; import { NotificationType, diff --git a/web/src/lib/components/admin-page/jobs/job-tile.svelte b/web/src/lib/components/admin-page/jobs/job-tile.svelte index 75d8ab6b81..42f489d41d 100644 --- a/web/src/lib/components/admin-page/jobs/job-tile.svelte +++ b/web/src/lib/components/admin-page/jobs/job-tile.svelte @@ -1,12 +1,10 @@