refactor: resolving PR comments

Reverting get() baseUrl overwrite in favour of a vanilla fetch() call

#943
This commit is contained in:
Hermanus Engelbrecht
2024-08-28 19:45:20 +02:00
parent 0e588bf315
commit a5979933f8
2 changed files with 25 additions and 17 deletions

View File

@@ -176,24 +176,33 @@ class EmbyConnectAPI extends ExternalAPI {
deviceId?: string
): Promise<LocalUserAuthExchangeResponse> {
try {
return this.get(
'/emby/Connect/Exchange',
const params = new URLSearchParams({
format: 'json',
ConnectUserId: userId,
'X-Emby-Client': 'Jellyseerr',
'X-Emby-Device-Id': deviceId ?? uniqueId(),
'X-Emby-Client-Version': getAppVersion(),
'X-Emby-Device-Name': 'Jellyseerr',
'X-Emby-Token': accessKey,
});
const response = await fetch(
`${getHostname()}/emby/Connect/Exchange?${params}`,
{
format: 'json',
ConnectUserId: userId,
'X-Emby-Client': 'Jellyseerr',
'X-Emby-Device-Id': deviceId ?? uniqueId(),
'X-Emby-Client-Version': getAppVersion(),
'X-Emby-Device-Name': 'Jellyseerr',
'X-Emby-Token': accessKey,
},
undefined,
{},
getHostname()
headers: {
'Content-Type': 'application/json',
},
}
);
if (!response.ok) {
throw new Error(response.statusText, { cause: response });
}
return await response.json();
} catch (e) {
logger.debug('Failed local user auth exchange');
throw new ApiError(e.cause?.status, ApiErrorCode.InvalidCredentials);
throw new ApiError(e.cause?.status, ApiErrorCode.InvalidAuthToken);
}
}
}

View File

@@ -47,8 +47,7 @@ class ExternalAPI {
endpoint: string,
params?: Record<string, string>,
ttl?: number,
config?: RequestInit,
overwriteBaseUrl?: string
config?: RequestInit
): Promise<T> {
const cacheKey = this.serializeCacheKey(endpoint, {
...this.params,
@@ -59,7 +58,7 @@ class ExternalAPI {
return cachedItem;
}
const url = this.formatUrl(endpoint, params, overwriteBaseUrl);
const url = this.formatUrl(endpoint, params);
const response = await this.fetch(url, {
...config,
headers: {