import Button from '@app/components/Common/Button'; import LoadingSpinner from '@app/components/Common/LoadingSpinner'; import PageTitle from '@app/components/Common/PageTitle'; import SensitiveInput from '@app/components/Common/SensitiveInput'; import Tooltip from '@app/components/Common/Tooltip'; import LanguageSelector from '@app/components/LanguageSelector'; import RegionSelector from '@app/components/RegionSelector'; import CopyButton from '@app/components/Settings/CopyButton'; import SettingsBadge from '@app/components/Settings/SettingsBadge'; import type { AvailableLocale } from '@app/context/LanguageContext'; import { availableLanguages } from '@app/context/LanguageContext'; import useLocale from '@app/hooks/useLocale'; import { Permission, useUser } from '@app/hooks/useUser'; import globalMessages from '@app/i18n/globalMessages'; import defineMessages from '@app/utils/defineMessages'; import { ArrowDownOnSquareIcon } from '@heroicons/react/24/outline'; import { ArrowPathIcon } from '@heroicons/react/24/solid'; import type { UserSettingsGeneralResponse } from '@server/interfaces/api/userSettingsInterfaces'; import type { MainSettings } from '@server/lib/settings'; import { Field, Form, Formik } from 'formik'; import { useIntl } from 'react-intl'; import { useToasts } from 'react-toast-notifications'; import useSWR, { mutate } from 'swr'; import * as Yup from 'yup'; const messages = defineMessages('components.Settings.SettingsMain', { general: 'General', generalsettings: 'General Settings', generalsettingsDescription: 'Configure global and default settings for Jellyseerr.', apikey: 'API Key', applicationTitle: 'Application Title', applicationurl: 'Application URL', region: 'Discover Region', regionTip: 'Filter content by regional availability', originallanguage: 'Discover Language', originallanguageTip: 'Filter content by original language', toastApiKeySuccess: 'New API key generated successfully!', toastApiKeyFailure: 'Something went wrong while generating a new API key.', toastSettingsSuccess: 'Settings saved successfully!', toastSettingsFailure: 'Something went wrong while saving settings.', hideAvailable: 'Hide Available Media', csrfProtection: 'Enable CSRF Protection', csrfProtectionTip: 'Set external API access to read-only (requires HTTPS)', csrfProtectionHoverTip: 'Do NOT enable this setting unless you understand what you are doing!', cacheImages: 'Enable Image Caching', cacheImagesTip: 'Cache externally sourced images (requires a significant amount of disk space)', trustProxy: 'Enable Proxy Support', trustProxyTip: 'Allow Jellyseerr to correctly register client IP addresses behind a proxy', validationApplicationTitle: 'You must provide an application title', validationApplicationUrl: 'You must provide a valid URL', validationApplicationUrlTrailingSlash: 'URL must not end in a trailing slash', partialRequestsEnabled: 'Allow Partial Series Requests', locale: 'Display Language', proxyEnabled: 'HTTP(S) Proxy', proxyHostname: 'Proxy Hostname', proxyPort: 'Proxy Port', proxySsl: 'Use SSL For Proxy', proxyUser: 'Proxy Username', proxyPassword: 'Proxy Password', proxyBypassFilter: 'Proxy Ignored Addresses', proxyBypassFilterTip: "Use ',' as a separator, and '*.' as a wildcard for subdomains", proxyBypassLocalAddresses: 'Bypass Proxy for Local Addresses', validationProxyPort: 'You must provide a valid port', }); const SettingsMain = () => { const { addToast } = useToasts(); const { user: currentUser, hasPermission: userHasPermission } = useUser(); const intl = useIntl(); const { setLocale } = useLocale(); const { data, error, mutate: revalidate, } = useSWR('/api/v1/settings/main'); const { data: userData } = useSWR( currentUser ? `/api/v1/user/${currentUser.id}/settings/main` : null ); const MainSettingsSchema = Yup.object().shape({ applicationTitle: Yup.string().required( intl.formatMessage(messages.validationApplicationTitle) ), applicationUrl: Yup.string() .url(intl.formatMessage(messages.validationApplicationUrl)) .test( 'no-trailing-slash', intl.formatMessage(messages.validationApplicationUrlTrailingSlash), (value) => !value || !value.endsWith('/') ), proxyPort: Yup.number().when('proxyEnabled', { is: (proxyEnabled: boolean) => proxyEnabled, then: Yup.number().required( intl.formatMessage(messages.validationProxyPort) ), }), }); const regenerate = async () => { try { const res = await fetch('/api/v1/settings/main/regenerate', { method: 'POST', }); if (!res.ok) throw new Error(); revalidate(); addToast(intl.formatMessage(messages.toastApiKeySuccess), { autoDismiss: true, appearance: 'success', }); } catch (e) { addToast(intl.formatMessage(messages.toastApiKeyFailure), { autoDismiss: true, appearance: 'error', }); } }; if (!data && !error) { return ; } return ( <>

{intl.formatMessage(messages.generalsettings)}

{intl.formatMessage(messages.generalsettingsDescription)}

{ try { const res = await fetch('/api/v1/settings/main', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ applicationTitle: values.applicationTitle, applicationUrl: values.applicationUrl, csrfProtection: values.csrfProtection, hideAvailable: values.hideAvailable, locale: values.locale, region: values.region, originalLanguage: values.originalLanguage, partialRequestsEnabled: values.partialRequestsEnabled, trustProxy: values.trustProxy, cacheImages: values.cacheImages, proxy: { enabled: values.proxyEnabled, hostname: values.proxyHostname, port: values.proxyPort, useSsl: values.proxySsl, user: values.proxyUser, password: values.proxyPassword, bypassFilter: values.proxyBypassFilter, bypassLocalAddresses: values.proxyBypassLocalAddresses, }, }), }); if (!res.ok) throw new Error(); mutate('/api/v1/settings/public'); mutate('/api/v1/status'); if (setLocale) { setLocale( (userData?.locale ? userData.locale : values.locale) as AvailableLocale ); } addToast(intl.formatMessage(messages.toastSettingsSuccess), { autoDismiss: true, appearance: 'success', }); } catch (e) { addToast(intl.formatMessage(messages.toastSettingsFailure), { autoDismiss: true, appearance: 'error', }); } finally { revalidate(); } }} > {({ errors, touched, isSubmitting, isValid, values, setFieldValue, }) => { return (
{userHasPermission(Permission.ADMIN) && (
)}
{errors.applicationTitle && touched.applicationTitle && typeof errors.applicationTitle === 'string' && (
{errors.applicationTitle}
)}
{errors.applicationUrl && touched.applicationUrl && typeof errors.applicationUrl === 'string' && (
{errors.applicationUrl}
)}
{ setFieldValue('trustProxy', !values.trustProxy); }} />
{ setFieldValue( 'csrfProtection', !values.csrfProtection ); }} />
{ setFieldValue('cacheImages', !values.cacheImages); }} />
{( Object.keys( availableLanguages ) as (keyof typeof availableLanguages)[] ).map((key) => ( ))}
{ setFieldValue('hideAvailable', !values.hideAvailable); }} />
{ setFieldValue( 'partialRequestsEnabled', !values.partialRequestsEnabled ); }} />
{ setFieldValue('proxyEnabled', !values.proxyEnabled); }} />
{values.proxyEnabled && ( <>
{errors.proxyHostname && touched.proxyHostname && typeof errors.proxyHostname === 'string' && (
{errors.proxyHostname}
)}
{errors.proxyPort && touched.proxyPort && typeof errors.proxyPort === 'string' && (
{errors.proxyPort}
)}
{ setFieldValue('proxySsl', !values.proxySsl); }} />
{errors.proxyUser && touched.proxyUser && typeof errors.proxyUser === 'string' && (
{errors.proxyUser}
)}
{errors.proxyPassword && touched.proxyPassword && typeof errors.proxyPassword === 'string' && (
{errors.proxyPassword}
)}
{errors.proxyBypassFilter && touched.proxyBypassFilter && typeof errors.proxyBypassFilter === 'string' && (
{errors.proxyBypassFilter}
)}
{ setFieldValue( 'proxyBypassLocalAddresses', !values.proxyBypassLocalAddresses ); }} />
)}
); }}
); }; export default SettingsMain;