feat(jellyfin): allow Jellyfin Guids with dashes for import-from-jellyfin endpoint (#2340)
This commit is contained in:
@@ -22,6 +22,7 @@ import { getSettings } from '@server/lib/settings';
|
|||||||
import logger from '@server/logger';
|
import logger from '@server/logger';
|
||||||
import { isAuthenticated } from '@server/middleware/auth';
|
import { isAuthenticated } from '@server/middleware/auth';
|
||||||
import { getHostname } from '@server/utils/getHostname';
|
import { getHostname } from '@server/utils/getHostname';
|
||||||
|
import { normalizeJellyfinGuid } from '@server/utils/jellyfin';
|
||||||
import { isOwnProfileOrAdmin } from '@server/utils/profileMiddleware';
|
import { isOwnProfileOrAdmin } from '@server/utils/profileMiddleware';
|
||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import gravatarUrl from 'gravatar-url';
|
import gravatarUrl from 'gravatar-url';
|
||||||
@@ -679,10 +680,20 @@ router.post(
|
|||||||
jellyfinClient.setUserId(admin.jellyfinUserId ?? '');
|
jellyfinClient.setUserId(admin.jellyfinUserId ?? '');
|
||||||
const jellyfinUsers = await jellyfinClient.getUsers();
|
const jellyfinUsers = await jellyfinClient.getUsers();
|
||||||
|
|
||||||
for (const jellyfinUserId of body.jellyfinUserIds) {
|
const jellyfinUsersById = new Map(
|
||||||
const jellyfinUser = jellyfinUsers.users.find(
|
jellyfinUsers.users.map((user) => [
|
||||||
(user) => user.Id === jellyfinUserId
|
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({
|
const user = await userRepository.findOne({
|
||||||
select: ['id', 'jellyfinUserId'],
|
select: ['id', 'jellyfinUserId'],
|
||||||
|
|||||||
15
server/utils/jellyfin.ts
Normal file
15
server/utils/jellyfin.ts
Normal file
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user