import { PencilIcon, PlusIcon, TrashIcon } from '@heroicons/react/solid'; import axios from 'axios'; import React, { useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import useSWR, { mutate } from 'swr'; import type { RadarrSettings, SonarrSettings, } from '../../../server/lib/settings'; import RadarrLogo from '../../assets/services/radarr.svg'; import SonarrLogo from '../../assets/services/sonarr.svg'; import globalMessages from '../../i18n/globalMessages'; import Alert from '../Common/Alert'; import Badge from '../Common/Badge'; import Button from '../Common/Button'; import LoadingSpinner from '../Common/LoadingSpinner'; import Modal from '../Common/Modal'; import PageTitle from '../Common/PageTitle'; import Transition from '../Transition'; import RadarrModal from './RadarrModal'; import SonarrModal from './SonarrModal'; const messages = defineMessages({ services: 'Services', radarrsettings: 'Radarr Settings', sonarrsettings: 'Sonarr Settings', serviceSettingsDescription: 'Configure your {serverType} server(s) below. You can connect multiple {serverType} servers, but only two of them can be marked as defaults (one non-4K and one 4K). Administrators are able to override the server used to process new requests prior to approval.', deleteserverconfirm: 'Are you sure you want to delete this server?', ssl: 'SSL', default: 'Default', default4k: 'Default 4K', is4k: '4K', address: 'Address', activeProfile: 'Active Profile', addradarr: 'Add Radarr Server', addsonarr: 'Add Sonarr Server', noDefaultServer: 'At least one {serverType} server must be marked as default in order for {mediaType} requests to be processed.', noDefaultNon4kServer: 'If you only have a single {serverType} server for both non-4K and 4K content (or if you only download 4K content), your {serverType} server should NOT be designated as a 4K server.', noDefault4kServer: 'A 4K {serverType} server must be marked as default in order to enable users to submit 4K {mediaType} requests.', mediaTypeMovie: 'movie', mediaTypeSeries: 'series', }); interface ServerInstanceProps { name: string; isDefault?: boolean; is4k?: boolean; hostname: string; port: number; isSSL?: boolean; externalUrl?: string; profileName: string; isSonarr?: boolean; onEdit: () => void; onDelete: () => void; } const ServerInstance: React.FC = ({ name, hostname, port, profileName, is4k = false, isDefault = false, isSSL = false, isSonarr = false, externalUrl, onEdit, onDelete, }) => { const intl = useIntl(); const internalUrl = (isSSL ? 'https://' : 'http://') + hostname + ':' + String(port); const serviceUrl = externalUrl ?? internalUrl; return (
  • {name}

    {isDefault && !is4k && ( {intl.formatMessage(messages.default)} )} {isDefault && is4k && ( {intl.formatMessage(messages.default4k)} )} {!isDefault && is4k && ( {intl.formatMessage(messages.is4k)} )} {isSSL && ( {intl.formatMessage(messages.ssl)} )}

    {intl.formatMessage(messages.address)} {internalUrl}

    {intl.formatMessage(messages.activeProfile)} {profileName}

    {isSonarr ? ( ) : ( )}
  • ); }; const SettingsServices: React.FC = () => { const intl = useIntl(); const { data: radarrData, error: radarrError, mutate: revalidateRadarr, } = useSWR('/api/v1/settings/radarr'); const { data: sonarrData, error: sonarrError, mutate: revalidateSonarr, } = useSWR('/api/v1/settings/sonarr'); const [editRadarrModal, setEditRadarrModal] = useState<{ open: boolean; radarr: RadarrSettings | null; }>({ open: false, radarr: null, }); const [editSonarrModal, setEditSonarrModal] = useState<{ open: boolean; sonarr: SonarrSettings | null; }>({ open: false, sonarr: null, }); const [deleteServerModal, setDeleteServerModal] = useState<{ open: boolean; type: 'radarr' | 'sonarr'; serverId: number | null; }>({ open: false, type: 'radarr', serverId: null, }); const deleteServer = async () => { await axios.delete( `/api/v1/settings/${deleteServerModal.type}/${deleteServerModal.serverId}` ); setDeleteServerModal({ open: false, serverId: null, type: 'radarr' }); revalidateRadarr(); revalidateSonarr(); mutate('/api/v1/settings/public'); }; return ( <>

    {intl.formatMessage(messages.radarrsettings)}

    {intl.formatMessage(messages.serviceSettingsDescription, { serverType: 'Radarr', })}

    {editRadarrModal.open && ( setEditRadarrModal({ open: false, radarr: null })} onSave={() => { revalidateRadarr(); mutate('/api/v1/settings/public'); setEditRadarrModal({ open: false, radarr: null }); }} /> )} {editSonarrModal.open && ( setEditSonarrModal({ open: false, sonarr: null })} onSave={() => { revalidateSonarr(); mutate('/api/v1/settings/public'); setEditSonarrModal({ open: false, sonarr: null }); }} /> )} deleteServer()} onCancel={() => setDeleteServerModal({ open: false, serverId: null, type: 'radarr', }) } title="Delete Server" iconSvg={} > {intl.formatMessage(messages.deleteserverconfirm)}
    {!radarrData && !radarrError && } {radarrData && !radarrError && ( <> {radarrData.length > 0 && (!radarrData.some((radarr) => radarr.isDefault) ? ( ) : !radarrData.some( (radarr) => radarr.isDefault && !radarr.is4k ) ? ( {msg} ); }, })} /> ) : ( radarrData.some((radarr) => radarr.is4k) && !radarrData.some( (radarr) => radarr.isDefault && radarr.is4k ) && ( ) ))}
      {radarrData.map((radarr) => ( setEditRadarrModal({ open: true, radarr })} onDelete={() => setDeleteServerModal({ open: true, serverId: radarr.id, type: 'radarr', }) } /> ))}
    )}

    {intl.formatMessage(messages.sonarrsettings)}

    {intl.formatMessage(messages.serviceSettingsDescription, { serverType: 'Sonarr', })}

    {!sonarrData && !sonarrError && } {sonarrData && !sonarrError && ( <> {sonarrData.length > 0 && (!sonarrData.some((sonarr) => sonarr.isDefault) ? ( ) : !sonarrData.some( (sonarr) => sonarr.isDefault && !sonarr.is4k ) ? ( {msg} ); }, })} /> ) : ( sonarrData.some((sonarr) => sonarr.is4k) && !sonarrData.some( (sonarr) => sonarr.isDefault && sonarr.is4k ) && ( ) ))}
      {sonarrData.map((sonarr) => ( setEditSonarrModal({ open: true, sonarr })} onDelete={() => setDeleteServerModal({ open: true, serverId: sonarr.id, type: 'sonarr', }) } /> ))}
    )}
    ); }; export default SettingsServices;