Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Jellyfin/Emby server type setup #685

Merged
merged 25 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
395a91c
feat: add Media Server Selection to Setup Page
fallenbagel Nov 17, 2023
504d8bd
Merge branch 'develop' into feat-server-type-setup
fallenbagel Mar 13, 2024
a4f1f12
feat(api): add severType to the api
fallenbagel Mar 13, 2024
45dbf84
refactor: use enums for serverType and rename selectedservice to serv…
fallenbagel Mar 13, 2024
7a50581
refactor(auth): jellyfin/emby authentication to set MediaServerType
fallenbagel Mar 13, 2024
1bc4bd3
fix: issue page formatMessage for 4k media
fallenbagel Mar 13, 2024
1aac3c5
refactor: cleaner way of handling serverType change using MediaServer…
fallenbagel Mar 13, 2024
19e2074
revert: removed conditional render of the auto-request permission
fallenbagel Mar 13, 2024
900e611
feat: add server type step to setup
gauthier-th Jun 4, 2024
635a5f0
chore: merge develop
gauthier-th Jul 15, 2024
5875b2b
Merge branch 'develop' into feat-server-type-setup
fallenbagel Jul 25, 2024
6207a6a
feat: migrate existing emby setups to use emby mediaServerType
fallenbagel Jul 25, 2024
6636aee
fix: scan jobs not running when media server type is emby
fallenbagel Jul 25, 2024
c3a6c7d
fix: emby media server type migration
fallenbagel Jul 25, 2024
b8042ab
refactor: change emby logo to full logo
fallenbagel Jul 25, 2024
5bcbc81
style: decrease emby logo size in setup screen
fallenbagel Jul 25, 2024
1cc43ce
refactor: use title case for servertype i18n message
fallenbagel Jul 25, 2024
2d9530c
refactor(i18n): fix a typo
fallenbagel Jul 25, 2024
e03edd2
refactor: use enums instead of numbers
fallenbagel Jul 25, 2024
2d802a5
chore: merge develop
gauthier-th Jul 29, 2024
58eb915
chore: merge develop
gauthier-th Aug 19, 2024
e531765
fix: remove old references to JELLYFIN_TYPE environment variable
gauthier-th Aug 19, 2024
d868082
fix: go back to the last step when refresh the setup page
gauthier-th Aug 19, 2024
dc34d6c
fix: move "scanning in background" tip next to the scanning section
gauthier-th Aug 19, 2024
dd2c752
fix: redirect the setup page when Jellyseerr is already setup
gauthier-th Aug 20, 2024
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
4 changes: 0 additions & 4 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ module.exports = {
commitTag: process.env.COMMIT_TAG || 'local',
forceIpv4First: process.env.FORCE_IPV4_FIRST === 'true' ? 'true' : 'false',
},
publicRuntimeConfig: {
// Will be available on both server and client
JELLYFIN_TYPE: process.env.JELLYFIN_TYPE,
},
images: {
remotePatterns: [
{ hostname: 'gravatar.com' },
Expand Down
2 changes: 2 additions & 0 deletions overseerr-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3586,6 +3586,8 @@ paths:
type: string
email:
type: string
serverType:
type: number
required:
- username
- password
Expand Down
5 changes: 5 additions & 0 deletions server/constants/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ export enum MediaServerType {
EMBY,
NOT_CONFIGURED,
}

export enum ServerType {
JELLYFIN = 'Jellyfin',
EMBY = 'Emby',
}
1 change: 1 addition & 0 deletions server/constants/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export enum UserType {
PLEX = 1,
LOCAL = 2,
JELLYFIN = 3,
EMBY = 4,
}
5 changes: 3 additions & 2 deletions server/entity/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ class Media {
}
} else {
const pageName =
process.env.JELLYFIN_TYPE === 'emby' ? 'item' : 'details';
getSettings().main.mediaServerType == MediaServerType.EMBY
? 'item'
: 'details';
const { serverId, externalHostname } = getSettings().jellyfin;

const jellyfinHost =
externalHostname && externalHostname.length > 0
? externalHostname
Expand Down
5 changes: 4 additions & 1 deletion server/lib/scanners/jellyfin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,10 @@ class JellyfinScanner {
public async run(): Promise<void> {
const settings = getSettings();

if (settings.main.mediaServerType != MediaServerType.JELLYFIN) {
if (
settings.main.mediaServerType != MediaServerType.JELLYFIN &&
settings.main.mediaServerType != MediaServerType.EMBY
) {
return;
}

Expand Down
17 changes: 17 additions & 0 deletions server/lib/settings/migrations/0002_emby_media_server_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MediaServerType } from '@server/constants/server';
import type { AllSettings } from '@server/lib/settings';

const migrateHostname = (settings: any): AllSettings => {
const oldMediaServerType = settings.main.mediaServerType;
console.log('Migrating media server type', oldMediaServerType);
if (
oldMediaServerType === MediaServerType.JELLYFIN &&
process.env.JELLYFIN_TYPE === 'emby'
) {
settings.main.mediaServerType = MediaServerType.EMBY;
}

return settings;
};

export default migrateHostname;
92 changes: 60 additions & 32 deletions server/routes/auth.ts

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this block on line 418 still be a TODO comment?

// TODO: If JELLYFIN_TYPE is set to 'emby' then set mediaServerType to EMBY
// if (process.env.JELLYFIN_TYPE === 'emby') {
//   settings.main.mediaServerType = MediaServerType.EMBY;
//   settings.save();
// }

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah thanks for pointing it out. That should be removed as we are now handling that using the settingsMigrator

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import JellyfinAPI from '@server/api/jellyfin';
import PlexTvAPI from '@server/api/plextv';
import { ApiErrorCode } from '@server/constants/error';
import { MediaServerType } from '@server/constants/server';
import { MediaServerType, ServerType } from '@server/constants/server';
import { UserType } from '@server/constants/user';
import { getRepository } from '@server/datasource';
import { User } from '@server/entity/User';
Expand Down Expand Up @@ -227,15 +227,20 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
urlBase?: string;
useSsl?: boolean;
email?: string;
serverType?: number;
};

//Make sure jellyfin login is enabled, but only if jellyfin is not already configured
//Make sure jellyfin login is enabled, but only if jellyfin && Emby is not already configured
if (
settings.main.mediaServerType !== MediaServerType.JELLYFIN &&
settings.main.mediaServerType != MediaServerType.NOT_CONFIGURED
settings.main.mediaServerType !== MediaServerType.EMBY &&
settings.main.mediaServerType != MediaServerType.NOT_CONFIGURED &&
settings.jellyfin.ip !== ''
) {
return res.status(500).json({ error: 'Jellyfin login is disabled' });
} else if (!body.username) {
}

if (!body.username) {
Dismissed Show dismissed Hide dismissed
return res.status(500).json({ error: 'You must provide an username' });
} else if (settings.jellyfin.ip !== '' && body.hostname) {
return res
Expand Down Expand Up @@ -273,7 +278,8 @@ 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 jellyfinserver = new JellyfinAPI(hostname ?? '', undefined, deviceId);

const jellyfinHost =
externalHostname && externalHostname.length > 0
? externalHostname
Expand Down Expand Up @@ -317,22 +323,47 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
);

// User doesn't exist, and there are no users in the database, we'll create the user
// with admin permission
settings.main.mediaServerType = MediaServerType.JELLYFIN;
user = new User({
email: body.email || account.User.Name,
jellyfinUsername: account.User.Name,
jellyfinUserId: account.User.Id,
jellyfinDeviceId: deviceId,
permissions: Permission.ADMIN,
avatar: account.User.PrimaryImageTag
? `${jellyfinHost}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`
: gravatarUrl(body.email || account.User.Name, {
default: 'mm',
size: 200,
}),
userType: UserType.JELLYFIN,
});
// with admin permissions
switch (body.serverType) {
case MediaServerType.EMBY:
settings.main.mediaServerType = MediaServerType.EMBY;
user = new User({
email: body.email || account.User.Name,
jellyfinUsername: account.User.Name,
jellyfinUserId: account.User.Id,
jellyfinDeviceId: deviceId,
jellyfinAuthToken: account.AccessToken,
permissions: Permission.ADMIN,
avatar: account.User.PrimaryImageTag
? `${jellyfinHost}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`
: gravatarUrl(body.email || account.User.Name, {
default: 'mm',
size: 200,
}),
userType: UserType.EMBY,
});
break;
case MediaServerType.JELLYFIN:
settings.main.mediaServerType = MediaServerType.JELLYFIN;
user = new User({
email: body.email || account.User.Name,
jellyfinUsername: account.User.Name,
jellyfinUserId: account.User.Id,
jellyfinDeviceId: deviceId,
jellyfinAuthToken: account.AccessToken,
permissions: Permission.ADMIN,
avatar: account.User.PrimaryImageTag
? `${jellyfinHost}/Users/${account.User.Id}/Images/Primary/?tag=${account.User.PrimaryImageTag}&quality=90`
: gravatarUrl(body.email || account.User.Name, {
default: 'mm',
size: 200,
}),
userType: UserType.JELLYFIN,
});
break;
default:
throw new Error('select_server_type');
}

// Create an API key on Jellyfin from this admin user
const jellyfinClient = new JellyfinAPI(
Expand Down Expand Up @@ -361,12 +392,12 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
logger.info(
`Found matching ${
settings.main.mediaServerType === MediaServerType.JELLYFIN
? 'Jellyfin'
: 'Emby'
? ServerType.JELLYFIN
: ServerType.EMBY
} user; updating user with ${
settings.main.mediaServerType === MediaServerType.JELLYFIN
? 'Jellyfin'
: 'Emby'
? ServerType.JELLYFIN
: ServerType.EMBY
}`,
{
label: 'API',
Expand All @@ -389,12 +420,6 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
user.username = '';
}

// TODO: If JELLYFIN_TYPE is set to 'emby' then set mediaServerType to EMBY
// if (process.env.JELLYFIN_TYPE === 'emby') {
// settings.main.mediaServerType = MediaServerType.EMBY;
// settings.save();
// }

await userRepository.save(user);
} else if (!settings.main.newPlexLogin) {
logger.warn(
Expand Down Expand Up @@ -432,7 +457,10 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
default: 'mm',
size: 200,
}),
userType: UserType.JELLYFIN,
userType:
settings.main.mediaServerType === MediaServerType.JELLYFIN
? UserType.JELLYFIN
: UserType.EMBY,
});
//initialize Jellyfin/Emby users with local login
const passedExplicitPassword = body.password && body.password.length > 0;
Expand Down
47 changes: 47 additions & 0 deletions src/assets/services/emby-icon-only.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading