Skip to content

Commit

Permalink
refactor: resolving PR comments
Browse files Browse the repository at this point in the history
Reverting get() baseUrl overwrite in favour of a vanilla fetch() call

#943
  • Loading branch information
pXius committed Aug 28, 2024
1 parent 0e588bf commit a597993
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
37 changes: 23 additions & 14 deletions server/api/embyconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions server/api/externalapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: {
Expand Down

0 comments on commit a597993

Please sign in to comment.