Skip to content

Commit fddbd7a

Browse files
committed
feat(users): add Jellyfin/Emby import sync to match Plex
Plex's import already refreshes already-known users' avatar/username on every click and hides them from the picker; Jellyfin/Emby only created new users and showed everyone regardless of import status. Also fixes a plexId string/int mismatch found while mirroring Plex's matching logic.
1 parent 62ed636 commit fddbd7a

8 files changed

Lines changed: 659 additions & 165 deletions

File tree

‎seerr-api.yml‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4431,18 +4431,23 @@ paths:
44314431
type: string
44324432
responses:
44334433
'201':
4434-
description: A list of the newly created users
4434+
description: The newly created users and a count of existing users that were refreshed
44354435
content:
44364436
application/json:
44374437
schema:
4438-
type: array
4439-
items:
4440-
$ref: '#/components/schemas/User'
4438+
type: object
4439+
properties:
4440+
createdUsers:
4441+
type: array
4442+
items:
4443+
$ref: '#/components/schemas/User'
4444+
refreshedUsers:
4445+
type: number
44414446
/user/import-from-jellyfin:
44424447
post:
44434448
summary: Import all users from Jellyfin
44444449
description: |
4445-
Fetches and imports users from the Jellyfin server.
4450+
Fetches and imports users from the Jellyfin/Emby server. If a list of Jellyfin user IDs is provided in the request body, only the specified users will be created as new accounts. Otherwise, all users will be imported.
44464451
44474452
Requires the `MANAGE_USERS` permission.
44484453
tags:
@@ -4460,13 +4465,18 @@ paths:
44604465
type: string
44614466
responses:
44624467
'201':
4463-
description: A list of the newly created users
4468+
description: The newly created users and a count of existing users that were refreshed
44644469
content:
44654470
application/json:
44664471
schema:
4467-
type: array
4468-
items:
4469-
$ref: '#/components/schemas/User'
4472+
type: object
4473+
properties:
4474+
createdUsers:
4475+
type: array
4476+
items:
4477+
$ref: '#/components/schemas/User'
4478+
refreshedUsers:
4479+
type: number
44704480
/user/registerPushSubscription:
44714481
post:
44724482
summary: Register a web push /user/registerPushSubscription

‎server/routes/avatarproxy.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function checkAvatarChanged(
4444

4545
let headResponse;
4646
try {
47-
headResponse = await axios.head(jellyfinAvatarUrl);
47+
headResponse = await axios.head(jellyfinAvatarUrl, { timeout: 5000 });
4848
if (headResponse.status !== 200) {
4949
return { changed: false };
5050
}

‎server/routes/settings/index.ts‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { appDataPath } from '@server/utils/appDataVolume';
3131
import { getAppVersion } from '@server/utils/appVersion';
3232
import { dnsCache } from '@server/utils/dnsCache';
3333
import { getHostname } from '@server/utils/getHostname';
34+
import { normalizeJellyfinGuid } from '@server/utils/jellyfin';
3435
import type { DnsEntries, DnsStats } from 'dns-caching';
3536
import { Router } from 'express';
3637
import rateLimit from 'express-rate-limit';
@@ -472,14 +473,40 @@ settingsRoutes.get('/jellyfin/users', async (req, res) => {
472473

473474
jellyfinClient.setUserId(admin.jellyfinUserId ?? '');
474475
const resp = await jellyfinClient.getUsers();
475-
const users = resp.users.map((user) => ({
476-
username: user.Name,
477-
id: user.Id,
478-
thumb: `/avatarproxy/${user.Id}`,
479-
email: user.Name,
480-
}));
481476

482-
return res.status(200).json(users);
477+
const jellyfinUserIds = resp.users
478+
.map((user) => normalizeJellyfinGuid(user.Id))
479+
.filter((id): id is string => !!id);
480+
481+
const existingUsers = jellyfinUserIds.length
482+
? await userRepository
483+
.createQueryBuilder('user')
484+
.select(['user.jellyfinUserId'])
485+
.where(
486+
"LOWER(REPLACE(user.jellyfinUserId, '-', '')) IN (:...jellyfinUserIds)",
487+
{ jellyfinUserIds }
488+
)
489+
.getMany()
490+
: [];
491+
const existingUserIds = new Set(
492+
existingUsers
493+
.map((user) => normalizeJellyfinGuid(user.jellyfinUserId))
494+
.filter((id): id is string => !!id)
495+
);
496+
497+
const unimportedUsers = resp.users
498+
.filter((user) => {
499+
const id = normalizeJellyfinGuid(user.Id);
500+
return !id || !existingUserIds.has(id);
501+
})
502+
.map((user) => ({
503+
username: user.Name,
504+
id: user.Id,
505+
thumb: `/avatarproxy/${user.Id}`,
506+
email: user.Name,
507+
}));
508+
509+
return res.status(200).json(unimportedUsers);
483510
});
484511

485512
settingsRoutes.get('/jellyfin/sync', (_req, res) => {

0 commit comments

Comments
 (0)