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
This commit is contained in:
Gauthier
2025-06-12 20:52:01 +02:00
committed by GitHub
parent 0bdc8a0334
commit c7284f473c
4 changed files with 13 additions and 10 deletions

View File

@@ -130,9 +130,7 @@ class JellyfinAPI extends ExternalAPI {
const safeDeviceId = const safeDeviceId =
deviceId && deviceId.length > 0 deviceId && deviceId.length > 0
? deviceId ? deviceId
: Buffer.from(`BOT_jellyseerr_fallback_${Date.now()}`).toString( : Buffer.from('BOT_jellyseerr').toString('base64');
'base64'
);
let authHeaderVal: string; let authHeaderVal: string;
if (authToken) { if (authToken) {

View File

@@ -277,11 +277,14 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
select: { id: true, jellyfinDeviceId: true }, select: { id: true, jellyfinDeviceId: true },
}); });
let deviceId = ''; let deviceId = 'BOT_jellyseerr';
if (user) { if (user && user.id === 1) {
deviceId = user.jellyfinDeviceId ?? ''; // Admin is always BOT_jellyseerr
} else { deviceId = 'BOT_jellyseerr';
deviceId = Buffer.from(`BOT_jellyseerr_${body.username ?? ''}`).toString( } else if (user && user.jellyfinDeviceId) {
deviceId = user.jellyfinDeviceId;
} else if (body.username) {
deviceId = Buffer.from(`BOT_jellyseerr_${body.username}`).toString(
'base64' 'base64'
); );
} }

View File

@@ -23,7 +23,7 @@ async function initAvatarImageProxy() {
select: ['id', 'jellyfinUserId', 'jellyfinDeviceId'], select: ['id', 'jellyfinUserId', 'jellyfinDeviceId'],
order: { id: 'ASC' }, order: { id: 'ASC' },
}); });
const deviceId = admin?.jellyfinDeviceId; const deviceId = admin?.jellyfinDeviceId || 'BOT_jellyseerr';
const authToken = getSettings().jellyfin.apiKey; const authToken = getSettings().jellyfin.apiKey;
_avatarImageProxy = new ImageProxy('avatar', '', { _avatarImageProxy = new ImageProxy('avatar', '', {
headers: { headers: {

View File

@@ -421,7 +421,9 @@ userSettingsRoutes.post<{ username: string; password: string }>(
const hostname = getHostname(); const hostname = getHostname();
const deviceId = Buffer.from( const deviceId = Buffer.from(
`BOT_jellyseerr_${req.user.username ?? ''}` req.user?.id === 1
? 'BOT_jellyseerr'
: `BOT_jellyseerr_${req.user.username ?? ''}`
).toString('base64'); ).toString('base64');
const jellyfinserver = new JellyfinAPI(hostname, undefined, deviceId); const jellyfinserver = new JellyfinAPI(hostname, undefined, deviceId);