diff --git a/server/lib/settings.ts b/server/lib/settings.ts index dda681df..98ac4363 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -645,8 +645,6 @@ class Settings { const oldJellyfinSettings = JSON.parse(data).jellyfin; // Migrate old settings - // TODO: Test this migration and the regex - console.log(oldJellyfinSettings); if (oldJellyfinSettings && oldJellyfinSettings.hostname) { // migrate old jellyfin hostname to ip and port and useSsl @@ -683,8 +681,6 @@ class Settings { delete oldJellyfinSettings.hostname; - console.log(this.data.jellyfin, oldJellyfinSettings.hostname); - this.data.jellyfin = Object.assign( {}, this.data.jellyfin, diff --git a/server/routes/auth.ts b/server/routes/auth.ts index 4c398060..57200730 100644 --- a/server/routes/auth.ts +++ b/server/routes/auth.ts @@ -443,9 +443,12 @@ authRoutes.post('/jellyfin', async (req, res, next) => { label: 'Auth', error: e.errorCode, status: e.statusCode, - hostname: `${body.useSsl ? 'https' : 'http'}://${body.hostname}:${ - body.port - }${body.urlBase}`, + hostname: getHostname({ + useSsl: body.useSsl, + ip: body.hostname, + port: body.port, + urlBase: body.urlBase, + }), } ); return next({ diff --git a/server/routes/settings/index.ts b/server/routes/settings/index.ts index 020f5a03..b2da75f8 100644 --- a/server/routes/settings/index.ts +++ b/server/routes/settings/index.ts @@ -25,6 +25,7 @@ import { getSettings } from '@server/lib/settings'; import logger from '@server/logger'; import { isAuthenticated } from '@server/middleware/auth'; import discoverSettingRoutes from '@server/routes/settings/discover'; +import { ApiError } from '@server/types/error'; import { appDataPath } from '@server/utils/appDataVolume'; import { getAppVersion } from '@server/utils/appVersion'; import { getHostname } from '@server/utils/getHostname'; @@ -275,11 +276,8 @@ settingsRoutes.post('/jellyfin', async (req, res, next) => { const result = await jellyfinClient.getSystemInfo(); - console.log(result); - - // TODO: use the apiErrorCodes if (!result?.data?.Id) { - throw new Error('Server not found'); + throw new ApiError(result?.status, ApiErrorCode.InvalidUrl); } settings.jellyfin.serverId = result.Id; @@ -364,12 +362,11 @@ settingsRoutes.get('/jellyfin/library', async (req, res, next) => { }); settingsRoutes.get('/jellyfin/users', async (req, res) => { - const { ip, port, useSsl, urlBase, externalHostname } = - getSettings().jellyfin; + const { externalHostname } = getSettings().jellyfin; const jellyfinHost = externalHostname && externalHostname.length > 0 ? externalHostname - : `${useSsl ? 'https' : 'http'}://${ip}:${port}${urlBase}`; + : getHostname(); const userRepository = getRepository(User); const admin = await userRepository.findOneOrFail({ diff --git a/server/routes/user/index.ts b/server/routes/user/index.ts index 37931f08..6b0953e6 100644 --- a/server/routes/user/index.ts +++ b/server/routes/user/index.ts @@ -20,6 +20,7 @@ import { hasPermission, Permission } from '@server/lib/permissions'; import { getSettings } from '@server/lib/settings'; import logger from '@server/logger'; import { isAuthenticated } from '@server/middleware/auth'; +import { getHostname } from '@server/utils/getHostname'; import { Router } from 'express'; import gravatarUrl from 'gravatar-url'; import { findIndex, sortBy } from 'lodash'; @@ -503,9 +504,8 @@ router.post( //const jellyfinUsersResponse = await jellyfinClient.getUsers(); const createdUsers: User[] = []; - const { ip, port, urlBase, useSsl, externalHostname } = - getSettings().jellyfin; - const hostname = `${useSsl ? 'https' : 'http'}://${ip}:${port}${urlBase}`; + const { externalHostname } = getSettings().jellyfin; + const hostname = getHostname(); const jellyfinHost = externalHostname && externalHostname.length > 0 diff --git a/src/components/Login/JellyfinLogin.tsx b/src/components/Login/JellyfinLogin.tsx index 0996bf0f..b606182a 100644 --- a/src/components/Login/JellyfinLogin.tsx +++ b/src/components/Login/JellyfinLogin.tsx @@ -126,7 +126,6 @@ const JellyfinLogin: React.FC = ({ email: values.email, }); } catch (e) { - console.log(e); let errorMessage = null; switch (e.response?.data?.message) { case ApiErrorCode.InvalidUrl: diff --git a/src/components/Settings/SettingsJellyfin.tsx b/src/components/Settings/SettingsJellyfin.tsx index 4a6d936a..9110d096 100644 --- a/src/components/Settings/SettingsJellyfin.tsx +++ b/src/components/Settings/SettingsJellyfin.tsx @@ -4,6 +4,7 @@ import LoadingSpinner from '@app/components/Common/LoadingSpinner'; import LibraryItem from '@app/components/Settings/LibraryItem'; import globalMessages from '@app/i18n/globalMessages'; import { ArrowDownOnSquareIcon } from '@heroicons/react/24/outline'; +import { ApiErrorCode } from '@server/constants/error'; import type { JellyfinSettings } from '@server/lib/settings'; import axios from 'axios'; import { Field, Formik } from 'formik'; @@ -43,7 +44,7 @@ const messages = defineMessages({ 'Custom authentication with Automatic Library Grouping not supported', jellyfinSyncFailedGenericError: 'Something went wrong while syncing libraries', - + invalidurlerror: 'Unable to connect to {mediaServerName} server.', syncing: 'Syncing', syncJellyfin: 'Sync Libraries', manualscanJellyfin: 'Manual Library Scan', @@ -148,15 +149,6 @@ const SettingsJellyfin: React.FC = ({ intl.formatMessage(messages.validationUrlTrailingSlash), (value) => !value || !value.endsWith('/') ), - - // jellyfinInternalUrl: Yup.string().matches( - // /^(https?:\/\/)?(?:[\w-]+\.)*[\w-]+(?::\d{2,5})?(?:\/[\w-]+)*(?:\/)?$/gm, - // intl.formatMessage(messages.validationUrl) - // ), - // jellyfinForgotPasswordUrl: Yup.string().matches( - // /^(https?:\/\/)?(?:[\w-]+\.)*[\w-]+(?::\d{2,5})?(?:\/[\w-]+)*(?:\/)?$/gm, - // intl.formatMessage(messages.validationUrl) - // ), }); const activeLibraries = @@ -479,18 +471,33 @@ const SettingsJellyfin: React.FC = ({ } ); } catch (e) { - addToast( - intl.formatMessage(messages.jellyfinSettingsFailure, { - mediaServerName: - publicRuntimeConfig.JELLYFIN_TYPE == 'emby' - ? 'Emby' - : 'Jellyfin', - }), - { - autoDismiss: true, - appearance: 'error', - } - ); + if (e.response?.data?.message === ApiErrorCode.InvalidUrl) { + addToast( + intl.formatMessage(messages.invalidurlerror, { + mediaServerName: + publicRuntimeConfig.JELLYFIN_TYPE == 'emby' + ? 'Emby' + : 'Jellyfin', + }), + { + autoDismiss: true, + appearance: 'error', + } + ); + } else { + addToast( + intl.formatMessage(messages.jellyfinSettingsFailure, { + mediaServerName: + publicRuntimeConfig.JELLYFIN_TYPE == 'emby' + ? 'Emby' + : 'Jellyfin', + }), + { + autoDismiss: true, + appearance: 'error', + } + ); + } } finally { revalidate(); }