diff --git a/server/api/servarr/base.ts b/server/api/servarr/base.ts index 75f138b57..9e4559339 100644 --- a/server/api/servarr/base.ts +++ b/server/api/servarr/base.ts @@ -2,6 +2,35 @@ import cacheManager, { AvailableCacheIds } from '../../lib/cache'; import { DVRSettings } from '../../lib/settings'; import ExternalAPI from '../externalapi'; +export interface SystemStatus { + version: string; + buildTime: Date; + isDebug: boolean; + isProduction: boolean; + isAdmin: boolean; + isUserInteractive: boolean; + startupPath: string; + appData: string; + osName: string; + osVersion: string; + isNetCore: boolean; + isMono: boolean; + isLinux: boolean; + isOsx: boolean; + isWindows: boolean; + isDocker: boolean; + mode: string; + branch: string; + authentication: string; + sqliteVersion: string; + migrationVersion: number; + urlBase: string; + runtimeVersion: string; + runtimeName: string; + startTime: Date; + packageUpdateMechanism: string; +} + export interface RootFolder { id: number; path: string; @@ -81,6 +110,18 @@ class ServarrBase extends ExternalAPI { this.apiName = apiName; } + public getSystemStatus = async (): Promise => { + try { + const response = await this.axios.get('/system/status'); + + return response.data; + } catch (e) { + throw new Error( + `[${this.apiName}] Failed to retrieve system status: ${e.message}` + ); + } + }; + public getProfiles = async (): Promise => { try { const data = await this.getRolling( diff --git a/server/routes/settings/radarr.ts b/server/routes/settings/radarr.ts index d250ea298..fd5791c5a 100644 --- a/server/routes/settings/radarr.ts +++ b/server/routes/settings/radarr.ts @@ -46,6 +46,7 @@ radarrRoutes.post< url: RadarrAPI.buildUrl(req.body, '/api/v3'), }); + const { urlBase } = await radarr.getSystemStatus(); const profiles = await radarr.getProfiles(); const folders = await radarr.getRootFolders(); const tags = await radarr.getTags(); @@ -57,6 +58,10 @@ radarrRoutes.post< path: folder.path, })), tags, + urlBase: + req.body.baseUrl && req.body.baseUrl !== '/' + ? req.body.baseUrl + : urlBase, }); } catch (e) { logger.error('Failed to test Radarr', { diff --git a/server/routes/settings/sonarr.ts b/server/routes/settings/sonarr.ts index 4f63ebb37..09baabd95 100644 --- a/server/routes/settings/sonarr.ts +++ b/server/routes/settings/sonarr.ts @@ -42,6 +42,7 @@ sonarrRoutes.post('/test', async (req, res, next) => { url: SonarrAPI.buildUrl(req.body, '/api/v3'), }); + const { urlBase } = await sonarr.getSystemStatus(); const profiles = await sonarr.getProfiles(); const folders = await sonarr.getRootFolders(); const languageProfiles = await sonarr.getLanguageProfiles(); @@ -55,6 +56,10 @@ sonarrRoutes.post('/test', async (req, res, next) => { })), languageProfiles, tags, + urlBase: + req.body.baseUrl && req.body.baseUrl !== '/' + ? req.body.baseUrl + : urlBase, }); } catch (e) { logger.error('Failed to test Sonarr', { diff --git a/src/components/Settings/RadarrModal/index.tsx b/src/components/Settings/RadarrModal/index.tsx index e25b8c538..1c3e6904c 100644 --- a/src/components/Settings/RadarrModal/index.tsx +++ b/src/components/Settings/RadarrModal/index.tsx @@ -82,6 +82,7 @@ interface TestResponse { id: number; label: string; }[]; + urlBase?: string; } interface RadarrModalProps { @@ -317,6 +318,9 @@ const RadarrModal: React.FC = ({ port: values.port, useSsl: values.ssl, }); + if (!values.baseUrl || values.baseUrl === '/') { + setFieldValue('baseUrl', testResponse.urlBase); + } } }} secondaryDisabled={ diff --git a/src/components/Settings/SonarrModal/index.tsx b/src/components/Settings/SonarrModal/index.tsx index 8514aa600..862d3cbe8 100644 --- a/src/components/Settings/SonarrModal/index.tsx +++ b/src/components/Settings/SonarrModal/index.tsx @@ -92,6 +92,7 @@ interface TestResponse { id: number; label: string; }[]; + urlBase?: string; } interface SonarrModalProps { @@ -348,6 +349,9 @@ const SonarrModal: React.FC = ({ port: values.port, useSsl: values.ssl, }); + if (!values.baseUrl || values.baseUrl === '/') { + setFieldValue('baseUrl', testResponse.urlBase); + } } }} secondaryDisabled={