refactor(web): use ImmichApi to create urls (#2435)

This commit is contained in:
Michel Heusschen 2023-05-14 04:52:29 +02:00 committed by GitHub
parent 15fa8250cb
commit 4524aa0d06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 53 additions and 51 deletions

View file

@ -2,6 +2,7 @@ import {
AlbumApi,
APIKeyApi,
AssetApi,
AssetApiFp,
AuthenticationApi,
Configuration,
ConfigurationParameters,
@ -11,11 +12,12 @@ import {
ServerInfoApi,
ShareApi,
SystemConfigApi,
ThumbnailFormat,
UserApi
UserApi,
UserApiFp
} from './open-api';
import { BASE_PATH } from './open-api/base';
import { DUMMY_BASE_URL, toPathString } from './open-api/common';
import type { ApiParams } from './types';
export class ImmichApi {
public userApi: UserApi;
@ -75,15 +77,24 @@ export class ImmichApi {
this.config.basePath = baseUrl;
}
public getAssetFileUrl(assetId: string, isThumb?: boolean, isWeb?: boolean, key?: string) {
public getAssetFileUrl(
...[assetId, isThumb, isWeb, key]: ApiParams<typeof AssetApiFp, 'serveFile'>
) {
const path = `/asset/file/${assetId}`;
return this.createUrl(path, { isThumb, isWeb, key });
}
public getAssetThumbnailUrl(assetId: string, format?: ThumbnailFormat, key?: string) {
public getAssetThumbnailUrl(
...[assetId, format, key]: ApiParams<typeof AssetApiFp, 'getAssetThumbnail'>
) {
const path = `/asset/thumbnail/${assetId}`;
return this.createUrl(path, { format, key });
}
public getProfileImageUrl(...[userId]: ApiParams<typeof UserApiFp, 'getProfileImage'>) {
const path = `/user/profile-image/${userId}`;
return this.createUrl(path);
}
}
export const api = new ImmichApi({ basePath: '/api' });