import { createForm } from '@felte/solid' import { validator } from '@felte/validator-zod' import { useNavigate } from '@solidjs/router' import { For, Show, createEffect, createResource, createSignal, onMount, } from 'solid-js' import { toast } from 'solid-toast' import { z } from 'zod' import { fetchBackendConfigAPI, fetchBackendVersionAPI, flushFakeIPDataAPI, flushingFakeIPData, isUpdateAvailableAPI, reloadConfigFileAPI, reloadingConfigFile, restartBackendAPI, restartingBackend, updateBackendConfigAPI, updateGEODatabasesAPI, updatingGEODatabases, upgradeBackendAPI, upgradingBackend, } from '~/apis' import { Button, ConfigTitle } from '~/components' import { LANG, MODE_OPTIONS, ROUTES, themes } from '~/constants' import { locale, setLocale, useI18n } from '~/i18n' import { autoSwitchTheme, endpoint, favDayTheme, favNightTheme, setAutoSwitchTheme, setFavDayTheme, setFavNightTheme, setSelectedEndpoint, setUseTwemoji, useRequest, useTwemoji, } from '~/signals' import type { DNSQuery } from '~/types' const dnsQueryFormSchema = z.object({ name: z.string(), type: z.string(), }) const DNSQueryForm = () => { const [t] = useI18n() const request = useRequest() const { form, isSubmitting } = createForm>( { extend: validator({ schema: dnsQueryFormSchema }), onSubmit: (values) => request .get('dns/query', { searchParams: { name: values.name, type: values.type }, }) .json() .then(({ Answer }) => setDNSQueryResult(Answer?.map(({ data }) => data) || []), ) .catch((err) => toast.error(err.message)), }, ) const [DNSQueryResult, setDNSQueryResult] = createSignal([]) return (
0}>
{(item) =>
{item}
}
) } const configFormSchema = z.object({ port: z.number(), 'socks-port': z.number(), 'redir-port': z.number(), 'tproxy-port': z.number(), 'mixed-port': z.number(), }) const ConfigForm = () => { const [t] = useI18n() const navigate = useNavigate() const portList = [ { label: () => t('port', { name: 'HTTP' }), key: 'port', onChange: (e: Event & { target: HTMLInputElement }) => void updateBackendConfigAPI('port', Number(e.target.value), refetch), }, { label: () => t('port', { name: 'Socks' }), key: 'socks-port', onChange: (e: Event & { target: HTMLInputElement }) => void updateBackendConfigAPI( 'socks-port', Number(e.target.value), refetch, ), }, { label: () => t('port', { name: 'Redir' }), key: 'redir-port', onChange: (e: Event & { target: HTMLInputElement }) => void updateBackendConfigAPI( 'redir-port', Number(e.target.value), refetch, ), }, { label: () => t('port', { name: 'TProxy' }), key: 'tproxy-port', onChange: (e: Event & { target: HTMLInputElement }) => void updateBackendConfigAPI( 'tproxy-port', Number(e.target.value), refetch, ), }, { label: () => t('port', { name: 'Mixed' }), key: 'mixed-port', onChange: (e: Event & { target: HTMLInputElement }) => void updateBackendConfigAPI( 'mixed-port', Number(e.target.value), refetch, ), }, ] const { form, setInitialValues, reset } = createForm< z.infer >({ extend: validator({ schema: configFormSchema }) }) const [configsData, { refetch }] = createResource(fetchBackendConfigAPI) createEffect(() => { const configs = configsData() if (configs) { setInitialValues(configs) reset() } }) return (
{(item) => (
)}
void updateBackendConfigAPI( 'tun', { enable: e.target.checked }, refetch, ) } />
void updateBackendConfigAPI( 'tun', { device: e.target.value }, refetch, ) } />
void updateBackendConfigAPI( 'interface-name', e.target.value, refetch, ) } />
) } const ConfigForXd = () => { const [t] = useI18n() const languages = [ { label: () => t('en'), value: LANG.EN, }, { label: () => t('zh'), value: LANG.ZH, }, ] return (
{t('autoSwitchTheme')} setAutoSwitchTheme(e.target.checked)} />
{t('favDayTheme')}
{t('favNightTheme')}
{t('useTwemoji')} setUseTwemoji(e.target.checked)} />
{t('switchLanguage')}
) } const Versions = () => { const [backendVersion, setBackendVersion] = createSignal('') const [isUpdateAvailable, setIsUpdateAvailable] = createSignal(false) onMount(async () => { const version = await fetchBackendVersionAPI() setBackendVersion(version) setIsUpdateAvailable(await isUpdateAvailableAPI(version)) }) return (
{import.meta.env.version}
{backendVersion()}

{endpoint()?.url}

) } export default () => { const [t] = useI18n() return (
{t('dnsQuery')} {t('coreConfig')} {t('xdConfig')} {t('version')}
) }