mirror of
https://github.com/immich-app/immich.git
synced 2025-11-18 07:22:40 +09:00
refactor: sdk init (#9563)
This commit is contained in:
@@ -13,12 +13,11 @@ npm i --save @immich/sdk
|
||||
For a more detailed example, check out the [`@immich/cli`](https://github.com/immich-app/immich/tree/main/cli).
|
||||
|
||||
```typescript
|
||||
import { defaults, getAllAlbums, getAllAssets, getMyUserInfo } from "@immich/sdk";
|
||||
import { getAllAlbums, getAllAssets, getMyUserInfo, init } from "@immich/sdk";
|
||||
|
||||
const API_KEY = "<API_KEY>"; // process.env.IMMICH_API_KEY
|
||||
|
||||
defaults.baseUrl = "https://demo.immich.app/api";
|
||||
defaults.headers = { "x-api-key": API_KEY };
|
||||
init({ baseUrl: "https://demo.immich.app/api", apiKey: API_KEY });
|
||||
|
||||
const user = await getMyUserInfo();
|
||||
const assets = await getAllAssets({ take: 1000 });
|
||||
|
||||
@@ -1,2 +1,25 @@
|
||||
import { defaults } from './fetch-client.js';
|
||||
|
||||
export * from './fetch-client.js';
|
||||
export * from './fetch-errors.js';
|
||||
|
||||
export interface InitOptions {
|
||||
baseUrl: string;
|
||||
apiKey: string;
|
||||
}
|
||||
|
||||
export const init = ({ baseUrl, apiKey }: InitOptions) => {
|
||||
setBaseUrl(baseUrl);
|
||||
setApiKey(apiKey);
|
||||
};
|
||||
|
||||
export const getBaseUrl = () => defaults.baseUrl;
|
||||
|
||||
export const setBaseUrl = (baseUrl: string) => {
|
||||
defaults.baseUrl = baseUrl;
|
||||
};
|
||||
|
||||
export const setApiKey = (apiKey: string) => {
|
||||
defaults.headers = defaults.headers || {};
|
||||
defaults.headers['x-api-key'] = apiKey;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user