Skip to content

Commit

Permalink
Merge pull request #240 from sambartik/revert-230-fix-jellyfin-emby-l…
Browse files Browse the repository at this point in the history
…inks

Fix jellyfin external url basepath being ignored
  • Loading branch information
Fallenbagel authored Oct 15, 2022
2 parents 15c79e0 + ab09664 commit d037d17
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
17 changes: 8 additions & 9 deletions server/entity/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
}
}
Expand Down
21 changes: 8 additions & 13 deletions server/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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';
}
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
});
Expand Down
10 changes: 5 additions & 5 deletions server/routes/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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,
}));
Expand Down
10 changes: 5 additions & 5 deletions server/routes/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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,
});
Expand Down

0 comments on commit d037d17

Please sign in to comment.