From db73aa7640ae5a8f9a82a1766cc301c6716c6bbf Mon Sep 17 00:00:00 2001 From: Gauthier Date: Wed, 4 Dec 2024 00:04:40 +0100 Subject: [PATCH] fix(setup): force fetch to use gzip for Emby auth This fixes an issue with the Fetch API that is unable to decode the response from Emby during setup. Related to https://github.com/nodejs/undici/issues/3762 --- server/api/jellyfin.ts | 16 +++++++++++++--- server/routes/auth.ts | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/server/api/jellyfin.ts b/server/api/jellyfin.ts index d0c4d7c74..622415b17 100644 --- a/server/api/jellyfin.ts +++ b/server/api/jellyfin.ts @@ -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'; @@ -117,11 +118,20 @@ class JellyfinAPI extends ExternalAPI { public async login( Username?: string, Password?: string, - ClientIP?: string + ClientIP?: string, + serverType?: MediaServerType ): Promise { 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( '/Users/AuthenticateByName', diff --git a/server/routes/auth.ts b/server/routes/auth.ts index 19e99a8ed..458aab4cb 100644 --- a/server/routes/auth.ts +++ b/server/routes/auth.ts @@ -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