Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions server/routes/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { getSettings } from '@server/lib/settings';
import logger from '@server/logger';
import { isAuthenticated } from '@server/middleware/auth';
import { getHostname } from '@server/utils/getHostname';
import { normalizeJellyfinGuid } from '@server/utils/jellyfin';
import { Router } from 'express';
import gravatarUrl from 'gravatar-url';
import { findIndex, sortBy } from 'lodash';
Expand Down Expand Up @@ -675,10 +676,20 @@ router.post(
jellyfinClient.setUserId(admin.jellyfinUserId ?? '');
const jellyfinUsers = await jellyfinClient.getUsers();

for (const jellyfinUserId of body.jellyfinUserIds) {
const jellyfinUser = jellyfinUsers.users.find(
(user) => user.Id === jellyfinUserId
);
const jellyfinUsersById = new Map(
jellyfinUsers.users.map((user) => [
normalizeJellyfinGuid(user.Id),
user,
])
);

for (const rawJellyfinUserId of body.jellyfinUserIds) {
const jellyfinUserId = normalizeJellyfinGuid(rawJellyfinUserId);
if (!jellyfinUserId) {
continue;
}

const jellyfinUser = jellyfinUsersById.get(jellyfinUserId);

const user = await userRepository.findOne({
select: ['id', 'jellyfinUserId'],
Expand Down
15 changes: 15 additions & 0 deletions server/utils/jellyfin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function normalizeJellyfinGuid(
value: string | null | undefined
): string | null {
if (!value) {
return null;
}

const normalized = value.replace(/-/g, '').toLowerCase();

if (!/^[0-9a-f]{32}$/.test(normalized)) {
return null;
}

return normalized;
}
Loading