diff --git a/server/entity/Media.ts b/server/entity/Media.ts index 48b04c785..cf6f5a280 100644 --- a/server/entity/Media.ts +++ b/server/entity/Media.ts @@ -200,21 +200,20 @@ class Media { const pageName = process.env.JELLYFIN_TYPE === 'emby' ? 'item' : 'details'; const { serverId, hostname, externalHostname } = getSettings().jellyfin; - const jellyfinHost = + let jellyfinHost = externalHostname && externalHostname.length > 0 ? externalHostname : hostname; + + jellyfinHost = jellyfinHost!.endsWith('/') + ? jellyfinHost!.slice(0, -1) + : jellyfinHost; + if (this.jellyfinMediaId) { - this.mediaUrl = new URL( - `/web/index.html#!/${pageName}?id=${this.jellyfinMediaId}&context=home&serverId=${serverId}`, - jellyfinHost - ).href; + this.mediaUrl = `${jellyfinHost}/web/index.html#!/${pageName}?id=${this.jellyfinMediaId}&context=home&serverId=${serverId}`; } if (this.jellyfinMediaId4k) { - this.mediaUrl4k = new URL( - `/web/index.html#!/${pageName}?id=${this.jellyfinMediaId4k}&context=home&serverId=${serverId}`, - jellyfinHost - ).href; + this.mediaUrl4k = `${jellyfinHost}/web/index.html#!/${pageName}?id=${this.jellyfinMediaId}&context=home&serverId=${serverId}`; } } } diff --git a/server/routes/auth.ts b/server/routes/auth.ts index 35f569fde..0280a4286 100644 --- a/server/routes/auth.ts +++ b/server/routes/auth.ts @@ -244,11 +244,15 @@ authRoutes.post('/jellyfin', async (req, res, next) => { } // First we need to attempt to log the user in to jellyfin const jellyfinserver = new JellyfinAPI(hostname ?? '', undefined, deviceId); - const jellyfinHost = + let jellyfinHost = externalHostname && externalHostname.length > 0 ? externalHostname : hostname; + jellyfinHost = jellyfinHost!.endsWith('/') + ? jellyfinHost!.slice(0, -1) + : jellyfinHost; + const account = await jellyfinserver.login(body.username, body.password); // Next let's see if the user already exists user = await userRepository.findOne({ @@ -263,10 +267,7 @@ authRoutes.post('/jellyfin', async (req, res, next) => { // Update the users avatar with their jellyfin profile pic (incase it changed) if (account.User.PrimaryImageTag) { - user.avatar = new URL( - `/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`, - jellyfinHost - ).href; + user.avatar = `${jellyfinHost}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`; } else { user.avatar = '/os_logo_square.png'; } @@ -312,10 +313,7 @@ authRoutes.post('/jellyfin', async (req, res, next) => { jellyfinAuthToken: account.AccessToken, permissions: Permission.ADMIN, avatar: account.User.PrimaryImageTag - ? new URL( - `/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`, - jellyfinHost - ).href + ? `${jellyfinHost}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90` : '/os_logo_square.png', userType: UserType.JELLYFIN, }); @@ -345,10 +343,7 @@ authRoutes.post('/jellyfin', async (req, res, next) => { jellyfinAuthToken: account.AccessToken, permissions: settings.main.defaultPermissions, avatar: account.User.PrimaryImageTag - ? new URL( - `/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`, - jellyfinHost - ).href + ? `${jellyfinHost}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90` : '/os_logo_square.png', userType: UserType.JELLYFIN, }); diff --git a/server/routes/settings/index.ts b/server/routes/settings/index.ts index 2d9fc2ffa..dc9dbcb42 100644 --- a/server/routes/settings/index.ts +++ b/server/routes/settings/index.ts @@ -307,11 +307,14 @@ settingsRoutes.get('/jellyfin/library', async (req, res) => { settingsRoutes.get('/jellyfin/users', async (req, res) => { const settings = getSettings(); const { hostname, externalHostname } = getSettings().jellyfin; - const jellyfinHost = + let jellyfinHost = externalHostname && externalHostname.length > 0 ? externalHostname : hostname; + jellyfinHost = jellyfinHost!.endsWith('/') + ? jellyfinHost!.slice(0, -1) + : jellyfinHost; const userRepository = getRepository(User); const admin = await userRepository.findOneOrFail({ select: ['id', 'jellyfinAuthToken', 'jellyfinDeviceId', 'jellyfinUserId'], @@ -330,10 +333,7 @@ settingsRoutes.get('/jellyfin/users', async (req, res) => { username: user.Name, id: user.Id, thumb: user.PrimaryImageTag - ? new URL( - `/Users/${user.Id}/Images/Primary/?tag=${user.PrimaryImageTag}&quality=90`, - jellyfinHost - ).href + ? `${jellyfinHost}/Users/${user.Id}/Images/Primary/?tag=${user.PrimaryImageTag}&quality=90` : '/os_logo_square.png', email: user.Name, })); diff --git a/server/routes/user/index.ts b/server/routes/user/index.ts index 258a3eae0..16d8a50be 100644 --- a/server/routes/user/index.ts +++ b/server/routes/user/index.ts @@ -497,11 +497,14 @@ router.post( //const jellyfinUsersResponse = await jellyfinClient.getUsers(); const createdUsers: User[] = []; const { hostname, externalHostname } = getSettings().jellyfin; - const jellyfinHost = + let jellyfinHost = externalHostname && externalHostname.length > 0 ? externalHostname : hostname; + jellyfinHost = jellyfinHost!.endsWith('/') + ? jellyfinHost!.slice(0, -1) + : jellyfinHost; jellyfinClient.setUserId(admin.jellyfinUserId ?? ''); const jellyfinUsers = await jellyfinClient.getUsers(); @@ -525,10 +528,7 @@ router.post( email: jellyfinUser?.Name, permissions: settings.main.defaultPermissions, avatar: jellyfinUser?.PrimaryImageTag - ? new URL( - `/Users/${jellyfinUser.Id}/Images/Primary/?tag=${jellyfinUser.PrimaryImageTag}&quality=90`, - jellyfinHost - ).href + ? `${jellyfinHost}/Users/${jellyfinUser.Id}/Images/Primary/?tag=${jellyfinUser.PrimaryImageTag}&quality=90` : '/os_logo_square.png', userType: UserType.JELLYFIN, });