2022-07-08 21:26:50 -05:00
|
|
|
import {
|
|
|
|
AlbumApi,
|
2023-01-02 15:22:33 -05:00
|
|
|
APIKeyApi,
|
2022-07-08 21:26:50 -05:00
|
|
|
AssetApi,
|
2023-05-14 04:52:29 +02:00
|
|
|
AssetApiFp,
|
2022-07-08 21:26:50 -05:00
|
|
|
AuthenticationApi,
|
|
|
|
Configuration,
|
2023-02-24 21:42:20 +01:00
|
|
|
ConfigurationParameters,
|
2022-10-06 11:25:54 -05:00
|
|
|
JobApi,
|
2022-11-14 21:24:25 -05:00
|
|
|
OAuthApi,
|
2023-05-17 13:07:17 -04:00
|
|
|
PersonApi,
|
2023-05-15 20:30:53 +03:00
|
|
|
PartnerApi,
|
2023-03-02 21:47:08 -05:00
|
|
|
SearchApi,
|
2022-07-08 21:26:50 -05:00
|
|
|
ServerInfoApi,
|
2023-01-09 14:16:08 -06:00
|
|
|
ShareApi,
|
2022-11-14 23:39:32 -05:00
|
|
|
SystemConfigApi,
|
2023-05-14 04:52:29 +02:00
|
|
|
UserApi,
|
2023-06-01 06:32:51 -04:00
|
|
|
UserApiFp,
|
|
|
|
JobName
|
2022-07-10 21:41:45 -05:00
|
|
|
} from './open-api';
|
2023-03-27 05:53:35 +02:00
|
|
|
import { BASE_PATH } from './open-api/base';
|
|
|
|
import { DUMMY_BASE_URL, toPathString } from './open-api/common';
|
2023-05-14 04:52:29 +02:00
|
|
|
import type { ApiParams } from './types';
|
2022-07-08 21:26:50 -05:00
|
|
|
|
2023-02-24 21:42:20 +01:00
|
|
|
export class ImmichApi {
|
2022-07-08 21:26:50 -05:00
|
|
|
public albumApi: AlbumApi;
|
|
|
|
public assetApi: AssetApi;
|
|
|
|
public authenticationApi: AuthenticationApi;
|
2023-05-15 20:30:53 +03:00
|
|
|
public jobApi: JobApi;
|
|
|
|
public keyApi: APIKeyApi;
|
2022-11-14 21:24:25 -05:00
|
|
|
public oauthApi: OAuthApi;
|
2023-05-15 20:30:53 +03:00
|
|
|
public partnerApi: PartnerApi;
|
2023-03-02 21:47:08 -05:00
|
|
|
public searchApi: SearchApi;
|
2022-07-08 21:26:50 -05:00
|
|
|
public serverInfoApi: ServerInfoApi;
|
2023-01-09 14:16:08 -06:00
|
|
|
public shareApi: ShareApi;
|
2023-05-17 13:07:17 -04:00
|
|
|
public personApi: PersonApi;
|
2023-05-15 20:30:53 +03:00
|
|
|
public systemConfigApi: SystemConfigApi;
|
|
|
|
public userApi: UserApi;
|
2022-10-06 11:25:54 -05:00
|
|
|
|
2023-02-24 21:42:20 +01:00
|
|
|
private config: Configuration;
|
|
|
|
|
|
|
|
constructor(params: ConfigurationParameters) {
|
|
|
|
this.config = new Configuration(params);
|
2022-07-08 21:26:50 -05:00
|
|
|
|
|
|
|
this.albumApi = new AlbumApi(this.config);
|
|
|
|
this.assetApi = new AssetApi(this.config);
|
|
|
|
this.authenticationApi = new AuthenticationApi(this.config);
|
2022-10-06 11:25:54 -05:00
|
|
|
this.jobApi = new JobApi(this.config);
|
2023-01-02 15:22:33 -05:00
|
|
|
this.keyApi = new APIKeyApi(this.config);
|
2023-05-15 20:30:53 +03:00
|
|
|
this.oauthApi = new OAuthApi(this.config);
|
|
|
|
this.partnerApi = new PartnerApi(this.config);
|
2023-03-02 21:47:08 -05:00
|
|
|
this.searchApi = new SearchApi(this.config);
|
2023-05-15 20:30:53 +03:00
|
|
|
this.serverInfoApi = new ServerInfoApi(this.config);
|
2023-01-09 14:16:08 -06:00
|
|
|
this.shareApi = new ShareApi(this.config);
|
2023-05-17 13:07:17 -04:00
|
|
|
this.personApi = new PersonApi(this.config);
|
2023-05-15 20:30:53 +03:00
|
|
|
this.systemConfigApi = new SystemConfigApi(this.config);
|
|
|
|
this.userApi = new UserApi(this.config);
|
2022-07-08 21:26:50 -05:00
|
|
|
}
|
|
|
|
|
2023-03-27 05:53:35 +02:00
|
|
|
private createUrl(path: string, params?: Record<string, unknown>) {
|
|
|
|
const searchParams = new URLSearchParams();
|
|
|
|
for (const key in params) {
|
|
|
|
const value = params[key];
|
|
|
|
if (value !== undefined && value !== null) {
|
|
|
|
searchParams.set(key, value.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const url = new URL(path, DUMMY_BASE_URL);
|
|
|
|
url.search = searchParams.toString();
|
|
|
|
|
|
|
|
return (this.config.basePath || BASE_PATH) + toPathString(url);
|
|
|
|
}
|
|
|
|
|
2022-07-08 21:26:50 -05:00
|
|
|
public setAccessToken(accessToken: string) {
|
|
|
|
this.config.accessToken = accessToken;
|
|
|
|
}
|
2022-07-26 12:28:07 -05:00
|
|
|
|
|
|
|
public removeAccessToken() {
|
|
|
|
this.config.accessToken = undefined;
|
|
|
|
}
|
2022-08-06 18:14:54 -05:00
|
|
|
|
|
|
|
public setBaseUrl(baseUrl: string) {
|
|
|
|
this.config.basePath = baseUrl;
|
|
|
|
}
|
2023-03-27 05:53:35 +02:00
|
|
|
|
2023-05-14 04:52:29 +02:00
|
|
|
public getAssetFileUrl(
|
|
|
|
...[assetId, isThumb, isWeb, key]: ApiParams<typeof AssetApiFp, 'serveFile'>
|
|
|
|
) {
|
2023-03-27 05:53:35 +02:00
|
|
|
const path = `/asset/file/${assetId}`;
|
|
|
|
return this.createUrl(path, { isThumb, isWeb, key });
|
|
|
|
}
|
|
|
|
|
2023-05-14 04:52:29 +02:00
|
|
|
public getAssetThumbnailUrl(
|
|
|
|
...[assetId, format, key]: ApiParams<typeof AssetApiFp, 'getAssetThumbnail'>
|
|
|
|
) {
|
2023-03-27 05:53:35 +02:00
|
|
|
const path = `/asset/thumbnail/${assetId}`;
|
|
|
|
return this.createUrl(path, { format, key });
|
|
|
|
}
|
2023-05-14 04:52:29 +02:00
|
|
|
|
|
|
|
public getProfileImageUrl(...[userId]: ApiParams<typeof UserApiFp, 'getProfileImage'>) {
|
|
|
|
const path = `/user/profile-image/${userId}`;
|
|
|
|
return this.createUrl(path);
|
|
|
|
}
|
2023-05-17 13:07:17 -04:00
|
|
|
|
|
|
|
public getPeopleThumbnailUrl(personId: string) {
|
|
|
|
const path = `/person/${personId}/thumbnail`;
|
|
|
|
return this.createUrl(path);
|
|
|
|
}
|
2023-06-01 06:32:51 -04:00
|
|
|
|
|
|
|
public getJobName(jobName: JobName) {
|
|
|
|
const names: Record<JobName, string> = {
|
|
|
|
[JobName.ThumbnailGeneration]: 'Generate Thumbnails',
|
|
|
|
[JobName.MetadataExtraction]: 'Extract Metadata',
|
|
|
|
[JobName.Sidecar]: 'Sidecar Metadata',
|
|
|
|
[JobName.ObjectTagging]: 'Tag Objects',
|
|
|
|
[JobName.ClipEncoding]: 'Encode Clip',
|
|
|
|
[JobName.RecognizeFaces]: 'Recognize Faces',
|
|
|
|
[JobName.VideoConversion]: 'Transcode Videos',
|
|
|
|
[JobName.StorageTemplateMigration]: 'Storage Template Migration',
|
|
|
|
[JobName.BackgroundTask]: 'Background Tasks',
|
|
|
|
[JobName.Search]: 'Search'
|
|
|
|
};
|
|
|
|
|
|
|
|
return names[jobName];
|
|
|
|
}
|
2022-07-08 21:26:50 -05:00
|
|
|
}
|
|
|
|
|
2023-02-24 21:42:20 +01:00
|
|
|
export const api = new ImmichApi({ basePath: '/api' });
|