Skip to content

Commit

Permalink
fix(setup): force fetch to use gzip for Emby auth
Browse files Browse the repository at this point in the history
This fixes an issue with the Fetch API that is unable to decode the response from Emby during setup.
Related to nodejs/undici#3762
  • Loading branch information
gauthier-th committed Dec 3, 2024
1 parent 17418f8 commit db73aa7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions server/api/jellyfin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import ExternalAPI from '@server/api/externalapi';
import { ApiErrorCode } from '@server/constants/error';
import { MediaServerType } from '@server/constants/server';
import availabilitySync from '@server/lib/availabilitySync';
import logger from '@server/logger';
import { ApiError } from '@server/types/error';
Expand Down Expand Up @@ -117,11 +118,20 @@ class JellyfinAPI extends ExternalAPI {
public async login(
Username?: string,
Password?: string,
ClientIP?: string
ClientIP?: string,
serverType?: MediaServerType
): Promise<JellyfinLoginResponse> {
const authenticate = async (useHeaders: boolean) => {
const headers: { [key: string]: string } =
useHeaders && ClientIP ? { 'X-Forwarded-For': ClientIP } : {};
let headers: { [key: string]: string } = {};
if (useHeaders && ClientIP) {
headers = { 'X-Forwarded-For': ClientIP };
}
if (serverType === MediaServerType.EMBY) {
headers = {
...headers,
'Accept-Encoding': 'gzip',
};
}

return this.post<JellyfinLoginResponse>(
'/Users/AuthenticateByName',
Expand Down
3 changes: 2 additions & 1 deletion server/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
const account = await jellyfinserver.login(
body.username,
body.password,
clientIp
clientIp,
body.serverType || settings.main.mediaServerType
);

// Next let's see if the user already exists
Expand Down

0 comments on commit db73aa7

Please # to comment.