From 87ae0be081fd66a29de96d0c654d22ecf7a04b59 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 14 Feb 2024 06:38:57 -0800 Subject: [PATCH] chore: enum support for new API (#7110) Co-authored-by: Jason Rasmussen --- open-api/bin/generate-open-api.sh | 2 +- open-api/typescript-sdk/fetch-client.ts | Bin 73637 -> 75384 bytes open-api/typescript-sdk/tsconfig.fetch.json | 2 +- web/src/api/index.ts | 3 - web/src/api/types.ts | 8 -- web/src/api/utils.ts | 63 --------------- web/src/{api/api.ts => lib/api/index.ts} | 8 +- .../admin-page/jobs/job-tile.svelte | 3 +- .../admin-page/jobs/jobs-panel.svelte | 3 +- .../settings/ffmpeg/ffmpeg-settings.svelte | 11 ++- .../settings/job-settings/job-settings.svelte | 6 +- .../logging-settings/logging-settings.svelte | 3 +- .../thumbnail/thumbnail-settings.svelte | 3 +- .../album-page/__tests__/album-card.spec.ts | 9 ++- .../components/album-page/album-card.svelte | 4 +- .../album-page/album-options.svelte | 6 +- .../components/album-page/album-viewer.svelte | 2 +- .../album-page/share-info-modal.svelte | 3 +- .../album-page/thumbnail-selection.svelte | 2 +- .../asset-viewer/activity-status.svelte | 2 +- .../asset-viewer/activity-viewer.svelte | 3 +- .../asset-viewer/album-list-item.svelte | 2 +- .../asset-viewer/asset-viewer-nav-bar.svelte | 2 +- .../asset-viewer/asset-viewer.svelte | 10 +-- .../asset-viewer/detail-panel.svelte | 9 ++- .../asset-viewer/panorama-viewer.svelte | 5 +- .../asset-viewer/photo-viewer.svelte | 3 +- .../asset-viewer/video-viewer.svelte | 2 +- .../assets/thumbnail/thumbnail.svelte | 2 +- .../faces-page/assign-face-side-panel.svelte | 9 ++- .../faces-page/edit-name-input.svelte | 2 +- .../faces-page/face-thumbnail.svelte | 2 +- .../faces-page/merge-face-selector.svelte | 3 +- .../faces-page/merge-suggestion-modal.svelte | 2 +- .../components/faces-page/people-card.svelte | 2 +- .../components/faces-page/people-list.svelte | 3 +- .../faces-page/person-side-panel.svelte | 11 ++- .../lib/components/forms/api-key-form.svelte | 10 +-- .../components/forms/api-key-secret.svelte | 6 +- .../forms/library-import-paths-form.svelte | 11 ++- .../forms/library-rename-form.svelte | 2 +- .../forms/library-scan-settings-form.svelte | 11 ++- .../lib/components/forms/login-form.svelte | 2 +- .../memory-page/memory-viewer.svelte | 10 ++- .../onboarding-storage-template.svelte | 3 +- .../photos-page/actions/add-to-album.svelte | 3 +- .../actions/asset-job-actions.svelte | 3 +- .../actions/remove-from-shared-link.svelte | 3 +- .../photos-page/asset-date-group.svelte | 13 ++-- .../components/photos-page/asset-grid.svelte | 8 +- .../asset-select-control-bar.svelte | 4 +- .../components/photos-page/memory-lane.svelte | 4 +- .../individual-shared-viewer.svelte | 3 +- .../album-selection-modal.svelte | 3 +- .../shared-components/change-location.svelte | 2 +- .../create-shared-link-modal.svelte | 4 +- .../asset-selection-viewer.svelte | 2 +- .../gallery-viewer/gallery-viewer.svelte | 13 ++-- .../shared-components/map/map.svelte | 4 +- .../navigation-bar/account-info-panel.svelte | 2 +- .../navigation-bar/avatar-selector.svelte | 4 +- .../profile-image-cropper.svelte | 3 +- .../search-bar/search-filter-box.svelte | 2 +- .../side-bar/side-bar.svelte | 3 +- .../version-announcement-box.svelte | 2 +- .../sharedlinks-page/shared-link-card.svelte | 9 ++- .../change-password-settings.svelte | 2 +- .../user-settings-page/device-card.svelte | 14 ++-- .../user-settings-page/device-list.svelte | 5 +- .../user-settings-page/library-list.svelte | 4 +- .../memories-settings.svelte | 3 +- .../user-settings-page/oauth-settings.svelte | 3 +- .../partner-selection-modal.svelte | 3 +- .../partner-settings.svelte | 10 ++- .../user-api-key-list.svelte | 15 ++-- .../user-settings-list.svelte | 15 ++-- web/src/lib/stores/asset-interaction.store.ts | 2 +- web/src/lib/stores/asset-viewing.store.ts | 3 +- web/src/lib/stores/assets.store.ts | 10 +-- web/src/lib/stores/memory.store.ts | 2 +- web/src/lib/stores/server-config.store.ts | 3 +- web/src/lib/stores/server-info.store.ts | 2 +- web/src/lib/stores/stacked-asset.store.ts | 2 +- web/src/lib/stores/user.store.ts | 2 +- web/src/lib/stores/websocket.ts | 4 +- web/src/lib/utils.ts | 72 +++++++++++++++++- web/src/lib/utils/asset-utils.spec.ts | 2 +- web/src/lib/utils/asset-utils.ts | 2 +- web/src/lib/utils/file-uploader.ts | 4 +- web/src/lib/utils/handle-error.ts | 2 +- web/src/lib/utils/person.ts | 2 +- web/src/lib/utils/timeline-util.ts | 2 +- web/src/routes/(user)/albums/+page.svelte | 45 ++++++----- .../(user)/albums/[albumId]/+page.svelte | 5 +- web/src/routes/(user)/map/+page.svelte | 3 +- web/src/routes/(user)/people/+page.svelte | 11 ++- .../(user)/people/[personId]/+page.svelte | 2 +- web/src/routes/(user)/places/+page.svelte | 12 +-- web/src/routes/(user)/search/+page.svelte | 20 ++--- .../routes/(user)/share/[key]/+page.svelte | 3 +- web/src/routes/(user)/share/[key]/+page.ts | 3 +- .../(user)/sharing/sharedlinks/+page.svelte | 4 +- web/src/routes/+error.svelte | 2 +- web/src/routes/admin/repair/+page.svelte | 8 +- .../routes/admin/system-settings/+page.svelte | 20 ++--- web/src/test-data/factories/user-factory.ts | 2 +- web/svelte.config.js | 1 - web/vite.config.js | 1 - 108 files changed, 353 insertions(+), 343 deletions(-) delete mode 100644 web/src/api/index.ts delete mode 100644 web/src/api/types.ts delete mode 100644 web/src/api/utils.ts rename web/src/{api/api.ts => lib/api/index.ts} (57%) diff --git a/open-api/bin/generate-open-api.sh b/open-api/bin/generate-open-api.sh index 76012383c..f0a211abe 100755 --- a/open-api/bin/generate-open-api.sh +++ b/open-api/bin/generate-open-api.sh @@ -19,7 +19,7 @@ function dart { function typescript { rm -rf ./typescript-sdk/client npx --yes @openapitools/openapi-generator-cli generate -g typescript-axios -i ./immich-openapi-specs.json -o ./typescript-sdk/axios-client --additional-properties=useSingleRequestParameter=true,supportsES6=true - npx --yes oazapfts --optimistic --argumentStyle=object immich-openapi-specs.json typescript-sdk/fetch-client.ts + npx --yes oazapfts --optimistic --argumentStyle=object --useEnumType immich-openapi-specs.json typescript-sdk/fetch-client.ts npm --prefix typescript-sdk ci && npm --prefix typescript-sdk run build } diff --git a/open-api/typescript-sdk/fetch-client.ts b/open-api/typescript-sdk/fetch-client.ts index 00b8c683264d5fb9bd8acad9691799f5ebcf5036..e37b43ca79dc074d8849723cadd3faf6ad3bcd84 100644 GIT binary patch delta 4021 zcmbVPJ8T?97?vNgkrRZloX98v9mlJ{2O>d8k&W_1y*I%ArNFLr(P$`?b0KWVL!Sw>$cx`uU;+{YE`` zrCC_0Ra>J*^P>w0jvjaG3n)DN`nkFF(fvDb|N8LB>fCb7-N?y-UQ*c_A96eQU?m5C zn%#&0+|K103i%BM1_2Kxh(dnllNEmIdm_x8qe0&gOUZK_?#d&&5{ap19dRIv^EL=s zqGup@>iJ&4g*Id%6D7~~1nJTemczsus_!c?zY$BbT9$hxVOUAOHa8Fv+#ujCw{7nP zu`?+VT(l#!Bj1OWpe@0?m}^ShlhT-jNkvV;&Ir<+J{L&K zP?&KUGtp}m45tcUvwx54((}#YPNmc(noXw5>o&DgCAGg41)(Q{UFvnZ&3cwx!)Ryd zs}56oSL@mqFiA)5SqAq|$GvK~(o7YP3`>GquUt*RW;j4=;#|Jj-LAB=H_ALGL&}kF zTRID++D7_8RJ~#22omORwsP}o_M`*uNY|W5Z4lhRf5f9^zbw4$< ztcs(o-6e{;=Y|91s5cwk?JS9ORZ|#{aMarZ9XGQ;r}Jg55Chii>53a#;aNAHG&RYG z1X`z4N$YCdFSS~+H&a0^77mE$DLhPeQ&mEc&M+g89r73?(y$jpPeU|-NjQm9@Tx);SL6EXNe%`osmnA%l>-h#&Ju%=c)M;ENl zAwtK&5Z#5PxW|}p zAvQ#ToY+2cd^vRl3Ivv|fb}Vv43e`h)$lb_0%z;wgSvkM$sPX&v1m+97X~V+_a)?> z=SKl!n%F^gZFX&09NAN=0iz5fR&&<|E4s|znLX0?bboZTucKm3g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KcB3e zoYQrnpyVbH;e{IQ60aKw#lbd7mA>|)rz)o}DA$+?08|Ap#TwJ}ry10c&^V?UZi{D@VaO~`e%KlHv`8)QRy>_XWm4S`g)!Py$lo&eq z(!Q>#PY9>l65W_{ZTU1Mu4>6)y4#sgnS;f9>g+LpUON+F0^$@H&(a}g&url9N~=Rq z_}s-8G%AF?f%W-|Lx@2*y*13CQjknC?d|nUVbtr5IJa2>YlL%}1PT$Vx-}%;V=l#V zR67OGBqYMDxc@lZuv;yL`*K&OkBs0Lmv{#l+oeeSgEcVi|Ds^$Mv3B${_PiZ}S>q86LL)byh^}#(YdPQk16sq4p#T5? diff --git a/open-api/typescript-sdk/tsconfig.fetch.json b/open-api/typescript-sdk/tsconfig.fetch.json index 58ef1ffa6..92d17ebda 100644 --- a/open-api/typescript-sdk/tsconfig.fetch.json +++ b/open-api/typescript-sdk/tsconfig.fetch.json @@ -1,5 +1,5 @@ { - "include": ["fetch.ts"], + "include": ["fetch.ts", "fetch-client.ts"], "compilerOptions": { "target": "esnext", "strict": true, diff --git a/web/src/api/index.ts b/web/src/api/index.ts deleted file mode 100644 index 886f439d8..000000000 --- a/web/src/api/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './api'; -export * from '@immich/sdk/axios'; -export * from './utils'; diff --git a/web/src/api/types.ts b/web/src/api/types.ts deleted file mode 100644 index 7a2ae17f6..000000000 --- a/web/src/api/types.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { Configuration } from '@immich/sdk/axios'; - -/* eslint-disable @typescript-eslint/no-explicit-any */ -export type ApiFp = (configuration: Configuration) => Record any>; - -export type OmitLast = T extends readonly [...infer U, any?] ? U : [...T]; - -export type ApiParams> = OmitLast[K]>>; diff --git a/web/src/api/utils.ts b/web/src/api/utils.ts deleted file mode 100644 index decfefc56..000000000 --- a/web/src/api/utils.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { finishOAuth, linkOAuthAccount, startOAuth, unlinkOAuthAccount } from '@immich/sdk'; -import { type UserResponseDto } from '@immich/sdk/axios'; -import type { AxiosError } from 'axios'; -import { - NotificationType, - notificationController, -} from '../lib/components/shared-components/notification/notification'; -import { handleError } from '../lib/utils/handle-error'; - -export type ApiError = AxiosError<{ message: string }>; - -export const copyToClipboard = async (secret: string) => { - try { - await navigator.clipboard.writeText(secret); - notificationController.show({ message: 'Copied to clipboard!', type: NotificationType.Info }); - } catch (error) { - handleError(error, 'Cannot copy to clipboard, make sure you are accessing the page through https'); - } -}; - -export const makeSharedLinkUrl = (externalDomain: string, key: string) => { - let url = externalDomain || window.location.origin; - if (!url.endsWith('/')) { - url += '/'; - } - return `${url}share/${key}`; -}; - -export const oauth = { - isCallback: (location: Location) => { - const search = location.search; - return search.includes('code=') || search.includes('error='); - }, - isAutoLaunchDisabled: (location: Location) => { - const values = ['autoLaunch=0', 'password=1', 'password=true']; - for (const value of values) { - if (location.search.includes(value)) { - return true; - } - } - return false; - }, - authorize: async (location: Location) => { - try { - const redirectUri = location.href.split('?')[0]; - const { url } = await startOAuth({ oAuthConfigDto: { redirectUri } }); - window.location.href = url; - return true; - } catch (error) { - handleError(error, 'Unable to login with OAuth'); - return false; - } - }, - login: (location: Location) => { - return finishOAuth({ oAuthCallbackDto: { url: location.href } }); - }, - link: (location: Location): Promise => { - return linkOAuthAccount({ oAuthCallbackDto: { url: location.href } }); - }, - unlink: () => { - return unlinkOAuthAccount(); - }, -}; diff --git a/web/src/api/api.ts b/web/src/lib/api/index.ts similarity index 57% rename from web/src/api/api.ts rename to web/src/lib/api/index.ts index 53340cb45..de8a5f722 100644 --- a/web/src/api/api.ts +++ b/web/src/lib/api/index.ts @@ -4,12 +4,10 @@ class ImmichApi { public downloadApi: DownloadApi; public assetApi: AssetApi; - private config: configuration.Configuration; - constructor(parameters: configuration.ConfigurationParameters) { - this.config = new configuration.Configuration(parameters); - this.downloadApi = new DownloadApi(this.config); - this.assetApi = new AssetApi(this.config); + const config = new configuration.Configuration(parameters); + this.downloadApi = new DownloadApi(config); + this.assetApi = new AssetApi(config); } } 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 42f489d41..9e4738669 100644 --- a/web/src/lib/components/admin-page/jobs/job-tile.svelte +++ b/web/src/lib/components/admin-page/jobs/job-tile.svelte @@ -3,8 +3,7 @@ import Button from '$lib/components/elements/buttons/button.svelte'; import Icon from '$lib/components/elements/icon.svelte'; import { locale } from '$lib/stores/preferences.store'; - import { type JobCommandDto, type JobCountsDto, type QueueStatusDto } from '@immich/sdk'; - import { JobCommand } from '@immich/sdk/axios'; + import { JobCommand, type JobCommandDto, type JobCountsDto, type QueueStatusDto } from '@immich/sdk'; import { mdiAlertCircle, mdiAllInclusive, diff --git a/web/src/lib/components/admin-page/jobs/jobs-panel.svelte b/web/src/lib/components/admin-page/jobs/jobs-panel.svelte index 7ab7c0462..60756166f 100644 --- a/web/src/lib/components/admin-page/jobs/jobs-panel.svelte +++ b/web/src/lib/components/admin-page/jobs/jobs-panel.svelte @@ -6,8 +6,7 @@ import { featureFlags } from '$lib/stores/server-config.store'; import { getJobName } from '$lib/utils'; import { handleError } from '$lib/utils/handle-error'; - import { sendJobCommand, type AllJobStatusResponseDto, type JobCommandDto } from '@immich/sdk'; - import { JobCommand, JobName } from '@immich/sdk/axios'; + import { JobCommand, JobName, sendJobCommand, type AllJobStatusResponseDto, type JobCommandDto } from '@immich/sdk'; import { mdiFaceRecognition, mdiFileJpgBox, diff --git a/web/src/lib/components/admin-page/settings/ffmpeg/ffmpeg-settings.svelte b/web/src/lib/components/admin-page/settings/ffmpeg/ffmpeg-settings.svelte index b0f5a9c08..cd73b77f4 100644 --- a/web/src/lib/components/admin-page/settings/ffmpeg/ffmpeg-settings.svelte +++ b/web/src/lib/components/admin-page/settings/ffmpeg/ffmpeg-settings.svelte @@ -1,7 +1,14 @@ diff --git a/web/src/lib/components/admin-page/settings/logging-settings/logging-settings.svelte b/web/src/lib/components/admin-page/settings/logging-settings/logging-settings.svelte index 85ea60545..f29e6f9ea 100644 --- a/web/src/lib/components/admin-page/settings/logging-settings/logging-settings.svelte +++ b/web/src/lib/components/admin-page/settings/logging-settings/logging-settings.svelte @@ -1,6 +1,5 @@