Skip to content

Commit

Permalink
fix(ui): fix avatar being broken when using local ip
Browse files Browse the repository at this point in the history
allow avatar url to use externalHostname when setup using local ip

fix #110
  • Loading branch information
Fallenbagel committed May 25, 2022
1 parent 4f972be commit 7eecc9d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
11 changes: 8 additions & 3 deletions server/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
settings.jellyfin.hostname !== ''
? settings.jellyfin.hostname
: body.hostname;
const { externalHostname } = getSettings().jellyfin;

// Try to find deviceId that corresponds to jellyfin user, else generate a new one
let user = await userRepository.findOne({
Expand All @@ -229,6 +230,10 @@ 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 =
externalHostname && externalHostname.length > 0
? externalHostname
: hostname;

const account = await jellyfinserver.login(body.username, body.password);
// Next let's see if the user already exists
Expand All @@ -244,7 +249,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 = `${hostname}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`;
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 @@ -290,7 +295,7 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
jellyfinAuthToken: account.AccessToken,
permissions: Permission.ADMIN,
avatar: account.User.PrimaryImageTag
? `${hostname}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`
? `${jellyfinHost}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`
: '/os_logo_square.png',
userType: UserType.JELLYFIN,
});
Expand Down Expand Up @@ -319,7 +324,7 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
jellyfinAuthToken: account.AccessToken,
permissions: settings.main.defaultPermissions,
avatar: account.User.PrimaryImageTag
? `${hostname}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`
? `${jellyfinHost}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`
: '/os_logo_square.png',
userType: UserType.JELLYFIN,
});
Expand Down
7 changes: 6 additions & 1 deletion server/routes/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ settingsRoutes.get('/jellyfin/library', async (req, res) => {

settingsRoutes.get('/jellyfin/users', async (req, res) => {
const settings = getSettings();
const { hostname, externalHostname } = getSettings().jellyfin;
const jellyfinHost =
externalHostname && externalHostname.length > 0
? externalHostname
: hostname;

const userRepository = getRepository(User);
const admin = await userRepository.findOneOrFail({
Expand All @@ -321,7 +326,7 @@ settingsRoutes.get('/jellyfin/users', async (req, res) => {
username: user.Name,
id: user.Id,
thumb: user.PrimaryImageTag
? `${settings.jellyfin.hostname}/Users/${user.Id}/Images/Primary/?tag=${user.PrimaryImageTag}&quality=90`
? `${jellyfinHost}/Users/${user.Id}/Images/Primary/?tag=${user.PrimaryImageTag}&quality=90`
: '/os_logo_square.png',
email: user.Name,
}));
Expand Down
7 changes: 6 additions & 1 deletion server/routes/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ router.post(

const jellyfinUsersResponse = await jellyfinClient.getUsers();
const createdUsers: User[] = [];
const { hostname, externalHostname } = getSettings().jellyfin;
const jellyfinHost =
externalHostname && externalHostname.length > 0
? externalHostname
: hostname;
for (const account of jellyfinUsersResponse.users) {
if (account.Name) {
const user = await userRepository
Expand All @@ -505,7 +510,7 @@ router.post(
.getOne();

const avatar = account.PrimaryImageTag
? `${settings.jellyfin.hostname}/Users/${account.Id}/Images/Primary/?tag=${account.PrimaryImageTag}&quality=90`
? `${jellyfinHost}/Users/${account.Id}/Images/Primary/?tag=${account.PrimaryImageTag}&quality=90`
: '/os_logo_square.png';

if (user) {
Expand Down

0 comments on commit 7eecc9d

Please sign in to comment.