mirror of
https://github.com/immich-app/immich.git
synced 2026-02-11 03:17:59 +03:00
chore: remove axios dependency from CLI (#6888)
This commit is contained in:
@@ -10,7 +10,6 @@ import {
|
||||
SystemConfigApi,
|
||||
UserApi,
|
||||
} from '@immich/sdk';
|
||||
import FormData from 'form-data';
|
||||
|
||||
export class ImmichApi {
|
||||
public userApi: UserApi;
|
||||
@@ -31,12 +30,9 @@ export class ImmichApi {
|
||||
) {
|
||||
this.config = new Configuration({
|
||||
basePath: instanceUrl,
|
||||
baseOptions: {
|
||||
headers: {
|
||||
'x-api-key': apiKey,
|
||||
},
|
||||
headers: {
|
||||
'x-api-key': apiKey,
|
||||
},
|
||||
formDataCtor: FormData,
|
||||
});
|
||||
|
||||
this.userApi = new UserApi(this.config);
|
||||
@@ -52,6 +48,9 @@ export class ImmichApi {
|
||||
|
||||
setApiKey(apiKey: string) {
|
||||
this.apiKey = apiKey;
|
||||
this.config.baseOptions.headers['x-api-key'] = apiKey;
|
||||
if (!this.config.headers) {
|
||||
throw new Error('missing headers');
|
||||
}
|
||||
this.config.headers['x-api-key'] = apiKey;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import {
|
||||
spyOnConsole,
|
||||
} from '../../test/cli-test-utils';
|
||||
|
||||
const mockPingServer = vi.fn(() => Promise.resolve({ data: { res: 'pong' } }));
|
||||
const mockUserInfo = vi.fn(() => Promise.resolve({ data: { email: 'admin@example.com' } }));
|
||||
const mockPingServer = vi.fn(() => Promise.resolve({ res: 'pong' }));
|
||||
const mockUserInfo = vi.fn(() => Promise.resolve({ email: 'admin@example.com' }));
|
||||
|
||||
vi.mock('@immich/sdk', async () => ({
|
||||
...(await vi.importActual('@immich/sdk')),
|
||||
|
||||
@@ -51,7 +51,7 @@ export class SessionService {
|
||||
|
||||
const api = new ImmichApi(instanceUrl, apiKey);
|
||||
|
||||
const { data: pingResponse } = await api.serverInfoApi.pingServer().catch((error) => {
|
||||
const pingResponse = await api.serverInfoApi.pingServer().catch((error) => {
|
||||
throw new Error(`Failed to connect to server ${api.instanceUrl}: ${error.message}`);
|
||||
});
|
||||
|
||||
@@ -68,7 +68,7 @@ export class SessionService {
|
||||
const api = new ImmichApi(instanceUrl, apiKey);
|
||||
|
||||
// Check if server and api key are valid
|
||||
const { data: userInfo } = await api.userApi.getMyUserInfo().catch((error) => {
|
||||
const userInfo = await api.userApi.getMyUserInfo().catch((error) => {
|
||||
throw new LoginError(`Failed to connect to server ${instanceUrl}: ${error.message}`);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user