chore: enum support for new API (#7110)

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
Ben McCann
2024-02-14 06:38:57 -08:00
committed by GitHub
parent 6f5648569a
commit 87ae0be081
108 changed files with 545 additions and 379 deletions

View File

@@ -1,7 +1,20 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { defaults } from '@immich/sdk';
import { AssetJobName, JobName, ThumbnailFormat, common } from '@immich/sdk/axios';
import { NotificationType, notificationController } from '$lib/components/shared-components/notification/notification';
import { handleError } from '$lib/utils/handle-error';
import {
AssetJobName,
JobName,
ThumbnailFormat,
defaults,
finishOAuth,
linkOAuthAccount,
startOAuth,
unlinkOAuthAccount,
type UserResponseDto,
} from '@immich/sdk';
import { common } from '@immich/sdk/axios';
import type { AxiosError } from 'axios';
import { get } from 'svelte/store';
interface UpdateParamAction {
@@ -121,3 +134,58 @@ export const getAssetJobMessage = (job: AssetJobName) => {
return messages[job];
};
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<UserResponseDto> => {
return linkOAuthAccount({ oAuthCallbackDto: { url: location.href } });
},
unlink: () => {
return unlinkOAuthAccount();
},
};