From c7284f473c43634b3a324f3b11a9a60990b3c0da Mon Sep 17 00:00:00 2001 From: Gauthier Date: Thu, 12 Jun 2025 20:52:01 +0200 Subject: [PATCH] fix(jellyfin): use the same deviceId for admins (#1710) * fix(jellyfin): use the same deviceId for admins This PR will make Jellyseerr use the same deviceId for the admin user everytime he logins to Jellyfin/Emby. The previous behavior with different deviceId was creating new entries on the media at every request. * fix: remove useless check --- server/api/jellyfin.ts | 4 +--- server/routes/auth.ts | 13 ++++++++----- server/routes/avatarproxy.ts | 2 +- server/routes/user/usersettings.ts | 4 +++- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/server/api/jellyfin.ts b/server/api/jellyfin.ts index 4c3a32f4..a8e52869 100644 --- a/server/api/jellyfin.ts +++ b/server/api/jellyfin.ts @@ -130,9 +130,7 @@ class JellyfinAPI extends ExternalAPI { const safeDeviceId = deviceId && deviceId.length > 0 ? deviceId - : Buffer.from(`BOT_jellyseerr_fallback_${Date.now()}`).toString( - 'base64' - ); + : Buffer.from('BOT_jellyseerr').toString('base64'); let authHeaderVal: string; if (authToken) { diff --git a/server/routes/auth.ts b/server/routes/auth.ts index 4452a655..b8e78a2d 100644 --- a/server/routes/auth.ts +++ b/server/routes/auth.ts @@ -277,11 +277,14 @@ authRoutes.post('/jellyfin', async (req, res, next) => { select: { id: true, jellyfinDeviceId: true }, }); - let deviceId = ''; - if (user) { - deviceId = user.jellyfinDeviceId ?? ''; - } else { - deviceId = Buffer.from(`BOT_jellyseerr_${body.username ?? ''}`).toString( + let deviceId = 'BOT_jellyseerr'; + if (user && user.id === 1) { + // Admin is always BOT_jellyseerr + deviceId = 'BOT_jellyseerr'; + } else if (user && user.jellyfinDeviceId) { + deviceId = user.jellyfinDeviceId; + } else if (body.username) { + deviceId = Buffer.from(`BOT_jellyseerr_${body.username}`).toString( 'base64' ); } diff --git a/server/routes/avatarproxy.ts b/server/routes/avatarproxy.ts index 15118d1d..fc48313e 100644 --- a/server/routes/avatarproxy.ts +++ b/server/routes/avatarproxy.ts @@ -23,7 +23,7 @@ async function initAvatarImageProxy() { select: ['id', 'jellyfinUserId', 'jellyfinDeviceId'], order: { id: 'ASC' }, }); - const deviceId = admin?.jellyfinDeviceId; + const deviceId = admin?.jellyfinDeviceId || 'BOT_jellyseerr'; const authToken = getSettings().jellyfin.apiKey; _avatarImageProxy = new ImageProxy('avatar', '', { headers: { diff --git a/server/routes/user/usersettings.ts b/server/routes/user/usersettings.ts index b3da5514..690cff83 100644 --- a/server/routes/user/usersettings.ts +++ b/server/routes/user/usersettings.ts @@ -421,7 +421,9 @@ userSettingsRoutes.post<{ username: string; password: string }>( const hostname = getHostname(); const deviceId = Buffer.from( - `BOT_jellyseerr_${req.user.username ?? ''}` + req.user?.id === 1 + ? 'BOT_jellyseerr' + : `BOT_jellyseerr_${req.user.username ?? ''}` ).toString('base64'); const jellyfinserver = new JellyfinAPI(hostname, undefined, deviceId);