Skip to content

Commit

Permalink
feat(servarr): auto fill base url when testing service if missing (#1995
Browse files Browse the repository at this point in the history
)

* feat(servarr): auto fill base url when testing service if missing

This will fill the base URL of the *arr service only if it's missing and the base URL hasn't been
provided beforehand

* fix(servarr): replace redundant check

* fix(servarr): suggested changes
  • Loading branch information
danshilm committed Oct 16, 2021
1 parent 54e9071 commit 739f667
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
41 changes: 41 additions & 0 deletions server/api/servarr/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +110,18 @@ class ServarrBase<QueueItemAppendT> extends ExternalAPI {
this.apiName = apiName;
}

public getSystemStatus = async (): Promise<SystemStatus> => {
try {
const response = await this.axios.get<SystemStatus>('/system/status');

return response.data;
} catch (e) {
throw new Error(
`[${this.apiName}] Failed to retrieve system status: ${e.message}`
);
}
};

public getProfiles = async (): Promise<QualityProfile[]> => {
try {
const data = await this.getRolling<QualityProfile[]>(
Expand Down
5 changes: 5 additions & 0 deletions server/routes/settings/radarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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', {
Expand Down
5 changes: 5 additions & 0 deletions server/routes/settings/sonarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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', {
Expand Down
4 changes: 4 additions & 0 deletions src/components/Settings/RadarrModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ interface TestResponse {
id: number;
label: string;
}[];
urlBase?: string;
}

interface RadarrModalProps {
Expand Down Expand Up @@ -317,6 +318,9 @@ const RadarrModal: React.FC<RadarrModalProps> = ({
port: values.port,
useSsl: values.ssl,
});
if (!values.baseUrl || values.baseUrl === '/') {
setFieldValue('baseUrl', testResponse.urlBase);
}
}
}}
secondaryDisabled={
Expand Down
4 changes: 4 additions & 0 deletions src/components/Settings/SonarrModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ interface TestResponse {
id: number;
label: string;
}[];
urlBase?: string;
}

interface SonarrModalProps {
Expand Down Expand Up @@ -348,6 +349,9 @@ const SonarrModal: React.FC<SonarrModalProps> = ({
port: values.port,
useSsl: values.ssl,
});
if (!values.baseUrl || values.baseUrl === '/') {
setFieldValue('baseUrl', testResponse.urlBase);
}
}
}}
secondaryDisabled={
Expand Down

0 comments on commit 739f667

Please sign in to comment.