/* * Copyright (C) Contributors to the Suwayomi project * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { useTranslation, Trans } from 'react-i18next'; import { useContext, useEffect } from 'react'; import { List, ListItem, ListItemText, Switch } from '@mui/material'; import ListSubheader from '@mui/material/ListSubheader'; import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext.tsx'; import { requestManager } from '@/lib/requests/RequestManager.ts'; import { useLocalStorage } from '@/util/useLocalStorage.tsx'; import { TextSetting } from '@/components/settings/text/TextSetting.tsx'; import { ServerSettings as GqlServerSettings } from '@/typings.ts'; import { NumberSetting } from '@/components/settings/NumberSetting.tsx'; import { MutableListSetting } from '@/components/settings/MutableListSetting.tsx'; type ServerSettingsType = Pick< GqlServerSettings, | 'ip' | 'port' | 'socksProxyEnabled' | 'socksProxyHost' | 'socksProxyPort' | 'debugLogsEnabled' | 'gqlDebugLogsEnabled' | 'systemTrayEnabled' | 'basicAuthEnabled' | 'basicAuthUsername' | 'basicAuthPassword' | 'maxSourcesInParallel' | 'localSourcePath' | 'extensionRepos' >; const extractDownloadSettings = (settings: GqlServerSettings): ServerSettingsType => ({ ip: settings.ip, port: settings.port, socksProxyEnabled: settings.socksProxyEnabled, socksProxyHost: settings.socksProxyHost, socksProxyPort: settings.socksProxyPort, debugLogsEnabled: settings.debugLogsEnabled, gqlDebugLogsEnabled: settings.gqlDebugLogsEnabled, systemTrayEnabled: settings.systemTrayEnabled, basicAuthEnabled: settings.basicAuthEnabled, basicAuthUsername: settings.basicAuthUsername, basicAuthPassword: settings.basicAuthPassword, maxSourcesInParallel: settings.maxSourcesInParallel, localSourcePath: settings.localSourcePath, extensionRepos: settings.extensionRepos, }); export const ServerSettings = () => { const { t } = useTranslation(); const { setTitle, setAction } = useContext(NavBarContext); useSetDefaultBackTo('settings'); useEffect(() => { setTitle(t('settings.server.title.settings')); setAction(null); }, [t]); const { data } = requestManager.useGetServerSettings(); const serverSettings = data ? extractDownloadSettings(data.settings) : undefined; const [mutateSettings] = requestManager.useUpdateServerSettings(); const [serverAddress, setServerAddress] = useLocalStorage('serverBaseURL', ''); const handleServerAddressChange = (address: string) => { const serverBaseUrl = address.replaceAll(/(\/)+$/g, ''); setServerAddress(serverBaseUrl); requestManager.updateClient({ baseURL: serverBaseUrl }); }; const updateSetting = ( setting: Setting, value: ServerSettingsType[Setting], ) => { mutateSettings({ variables: { input: { settings: { [setting]: value } } } }); }; return ( {t('global.label.client')} } > {t('settings.server.requests.title')} } > updateSetting('maxSourcesInParallel', parallelSources)} /> {t('extension.title')} } > Suwayomi does not provide any support for 3rd party repositories or extensions!
Use with caution as there could be malicious actors making those repositories.
You as the user need to verify the security and that you trust any repository or extension. } handleChange={(repos) => { updateSetting('extensionRepos', repos); requestManager.clearExtensionCache(); }} values={serverSettings?.extensionRepos} addItemButtonTitle={t('extension.settings.repositories.custom.dialog.action.button.add')} placeholder="https://github.com/MY_ACCOUNT/MY_REPO/tree/repo" validateItem={(repo) => !!repo.match( /https:\/\/(www\.|raw\.)?(github|githubusercontent)\.com\/([^/]+)\/([^/]+)((\/tree|\/blob)?\/([^/\n]*))?(\/([^/\n]*\.json)?)?/g, ) } invalidItemError={t('extension.settings.repositories.custom.error.label.invalid_url')} />
{t('source.local_source.title')} } > updateSetting('localSourcePath', path)} /> {t('settings.server.address.server.title')} } > updateSetting('ip', ip)} value={serverSettings?.ip} placeholder="0.0.0.0" /> updateSetting('port', port)} value={serverSettings?.port ?? 4567} defaultValue={4567} valueUnit={t('settings.server.address.server.label.port')} /> {t('settings.server.socks_proxy.title')} } > updateSetting('socksProxyEnabled', e.target.checked)} /> updateSetting('socksProxyHost', proxyHost)} disabled={!serverSettings?.socksProxyEnabled} /> updateSetting('socksProxyPort', proxyPort)} disabled={!serverSettings?.socksProxyEnabled} /> {t('settings.server.auth.title')} } > updateSetting('basicAuthEnabled', e.target.checked)} /> updateSetting('basicAuthUsername', authUsername)} disabled={!serverSettings?.basicAuthEnabled} /> updateSetting('basicAuthPassword', authPassword)} disabled={!serverSettings?.basicAuthEnabled} /> {t('settings.server.misc.title')} } > updateSetting('debugLogsEnabled', e.target.checked)} /> updateSetting('gqlDebugLogsEnabled', e.target.checked)} /> updateSetting('systemTrayEnabled', e.target.checked)} />
); };