diff --git a/server/routes/service.ts b/server/routes/service.ts index 083e1eb57..8f6c92b0d 100644 --- a/server/routes/service.ts +++ b/server/routes/service.ts @@ -123,9 +123,13 @@ serviceRoutes.get<{ sonarrId: string }>( }); try { + const systemStatus = await sonarr.getSystemStatus(); + const sonarrMajorVersion = Number(systemStatus.version.split('.')[0]); + const profiles = await sonarr.getProfiles(); const rootFolders = await sonarr.getRootFolders(); - const languageProfiles = await sonarr.getLanguageProfiles(); + const languageProfiles = + sonarrMajorVersion <= 3 ? await sonarr.getLanguageProfiles() : null; const tags = await sonarr.getTags(); return res.status(200).json({ diff --git a/server/routes/settings/sonarr.ts b/server/routes/settings/sonarr.ts index 358d07002..8c74fa20a 100644 --- a/server/routes/settings/sonarr.ts +++ b/server/routes/settings/sonarr.ts @@ -43,13 +43,14 @@ sonarrRoutes.post('/test', async (req, res, next) => { url: SonarrAPI.buildUrl(req.body, '/api/v3'), }); - const urlBase = await sonarr - .getSystemStatus() - .then((value) => value.urlBase) - .catch(() => req.body.baseUrl); + const systemStatus = await sonarr.getSystemStatus(); + const sonarrMajorVersion = Number(systemStatus.version.split('.')[0]); + + const urlBase = systemStatus.urlBase; const profiles = await sonarr.getProfiles(); const folders = await sonarr.getRootFolders(); - const languageProfiles = await sonarr.getLanguageProfiles(); + const languageProfiles = + sonarrMajorVersion <= 3 ? await sonarr.getLanguageProfiles() : null; const tags = await sonarr.getTags(); return res.status(200).json({ diff --git a/src/components/Settings/SonarrModal/index.tsx b/src/components/Settings/SonarrModal/index.tsx index ed6d1f564..f2bcd4dbc 100644 --- a/src/components/Settings/SonarrModal/index.tsx +++ b/src/components/Settings/SonarrModal/index.tsx @@ -86,10 +86,12 @@ interface TestResponse { id: number; path: string; }[]; - languageProfiles: { - id: number; - name: string; - }[]; + languageProfiles: + | { + id: number; + name: string; + }[] + | null; tags: { id: number; label: string; @@ -112,7 +114,7 @@ const SonarrModal = ({ onClose, sonarr, onSave }: SonarrModalProps) => { const [testResponse, setTestResponse] = useState({ profiles: [], rootFolders: [], - languageProfiles: [], + languageProfiles: null, tags: [], }); const SonarrSettingsSchema = Yup.object().shape({ @@ -137,9 +139,11 @@ const SonarrModal = ({ onClose, sonarr, onSave }: SonarrModalProps) => { activeProfileId: Yup.string().required( intl.formatMessage(messages.validationProfileRequired) ), - activeLanguageProfileId: Yup.number().required( - intl.formatMessage(messages.validationLanguageProfileRequired) - ), + activeLanguageProfileId: testResponse.languageProfiles + ? Yup.number().required( + intl.formatMessage(messages.validationLanguageProfileRequired) + ) + : Yup.number(), externalUrl: Yup.string() .url(intl.formatMessage(messages.validationApplicationUrl)) .test( @@ -658,54 +662,56 @@ const SonarrModal = ({ onClose, sonarr, onSave }: SonarrModalProps) => { )} -
- -
-
- - - {testResponse.languageProfiles.length > 0 && - testResponse.languageProfiles.map((language) => ( - - ))} - + {testResponse.languageProfiles && ( +
+ +
+
+ + + {testResponse.languageProfiles.length > 0 && + testResponse.languageProfiles.map((language) => ( + + ))} + +
+ {errors.activeLanguageProfileId && + touched.activeLanguageProfileId && ( +
+ {errors.activeLanguageProfileId} +
+ )}
- {errors.activeLanguageProfileId && - touched.activeLanguageProfileId && ( -
- {errors.activeLanguageProfileId} -
- )}
-
+ )}
-
- -
-
- - - {testResponse.languageProfiles.length > 0 && - testResponse.languageProfiles.map((language) => ( - - ))} - + {testResponse.languageProfiles && ( +
+ +
+
+ + + {testResponse.languageProfiles.length > 0 && + testResponse.languageProfiles.map((language) => ( + + ))} + +
+ {errors.activeAnimeLanguageProfileId && + touched.activeAnimeLanguageProfileId && ( +
+ {errors.activeAnimeLanguageProfileId} +
+ )}
- {errors.activeAnimeLanguageProfileId && - touched.activeAnimeLanguageProfileId && ( -
- {errors.activeAnimeLanguageProfileId} -
- )}
-
+ )}