fix(jellyfinapi): fix api key migration

This commit is contained in:
Gauthier
2024-08-05 16:13:32 +02:00
parent 35342a945d
commit 3dafc362ed
3 changed files with 10 additions and 11 deletions

View File

@@ -85,7 +85,7 @@ class ExternalAPI {
protected async post<T>(
endpoint: string,
data: Record<string, unknown>,
data?: Record<string, unknown>,
params?: Record<string, string>,
ttl?: number,
config?: RequestInit
@@ -107,7 +107,7 @@ class ExternalAPI {
...this.defaultHeaders,
...config?.headers,
},
body: JSON.stringify(data),
body: data ? JSON.stringify(data) : undefined,
});
if (!response.ok) {
const text = await response.text();
@@ -286,7 +286,12 @@ class ExternalAPI {
...this.params,
...params,
});
return `${href}?${searchParams.toString()}`;
return (
href +
(searchParams.toString().length
? '?' + searchParams.toString()
: searchParams.toString())
);
}
private serializeCacheKey(

View File

@@ -408,8 +408,8 @@ class JellyfinAPI extends ExternalAPI {
public async createApiToken(appName: string): Promise<string> {
try {
await this.axios.post(`/Auth/Keys?App=${appName}`);
const apiKeys = await this.get<any>('/Auth/Keys');
await this.post(`/Auth/Keys?App=${appName}`);
const apiKeys = await this.get<any>(`/Auth/Keys`);
return apiKeys.Items.reverse().find(
(item: any) => item.AppName === appName
).AccessToken;

View File

@@ -658,7 +658,6 @@ class Settings {
}
}
let loaded = false;
let settings: Settings | undefined;
export const getSettings = (initialSettings?: AllSettings): Settings => {
@@ -666,11 +665,6 @@ export const getSettings = (initialSettings?: AllSettings): Settings => {
settings = new Settings(initialSettings);
}
if (!loaded) {
settings.load();
loaded = true;
}
return settings;
};