import { createForm } from '@felte/solid' import { validator } from '@felte/validator-zod' import { useI18n } from '@solid-primitives/i18n' import { useNavigate } from '@solidjs/router' import { For, ParentComponent, Show, children, createSignal, onMount, } from 'solid-js' import { z } from 'zod' import { Button } from '~/components' import { LANG, PROXIES_ORDERING_TYPE, PROXIES_PREVIEW_TYPE, ROUTES, TAILWINDCSS_SIZE, themes, } from '~/constants' import { applyThemeByMode, autoCloseConns, autoSwitchTheme, favDayTheme, favNightTheme, latencyTestTimeoutDuration, proxiesOrderingType, proxiesPreviewType, renderInTwoColumns, renderRulesAndProviderInTwoColumns, setAutoCloseConns, setAutoSwitchTheme, setFavDayTheme, setFavNightTheme, setLatencyTestTimeoutDuration, setProxiesOrderingType, setProxiesPreviewType, setRenderInTwoColumns, setRenderRulesAndProviderInTwoColumns, setSelectedEndpoint, setTableSize, setTwemoji, setUrlForLatencyTest, tableSize, urlForLatencyTest, useRequest, useTwemoji, } from '~/signals' import type { DNSQuery, Config as IConfig } from '~/types' const dnsQueryFormSchema = z.object({ name: z.string(), type: z.string(), }) const ConfigTitle: ParentComponent = (props) => (
{children(() => props.children)()}
) const DNSQueryForm = () => { const [t] = useI18n() const request = useRequest() const { form, isSubmitting } = createForm>( { extend: validator({ schema: dnsQueryFormSchema }), onSubmit: async (values) => { request .get('dns/query', { searchParams: { name: values.name, type: values.type }, }) .json() .then(({ Answer }) => setDNSQueryResult(Answer?.map(({ data }) => data) || []), ) }, }, ) 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 request = useRequest() const portsList = [ { label: 'Http Port', key: 'port', }, { label: 'Socks Port', key: 'socks-port', }, { label: 'Redir Port', key: 'redir-port', }, { label: 'Tproxy Port', key: 'tproxy-port', }, { label: 'Mixed Port', key: 'mixed-port', }, ] const { form, setInitialValues, reset } = createForm< z.infer >({ extend: validator({ schema: configFormSchema }) }) onMount(async () => { const configs = await request.get('configs').json() setInitialValues(configs) reset() }) const [updatingGEODatabases, setUpdatingGEODatabases] = createSignal(false) const [upgrading, setUpgrading] = createSignal(false) const [restarting, setRestarting] = createSignal(false) const onUpdateGEODatabases = async () => { setUpdatingGEODatabases(true) try { await request.post('configs/geo') } catch {} setUpdatingGEODatabases(false) } const onUpgrade = async () => { setUpgrading(true) try { await request.post('upgrade') } catch {} setUpgrading(false) } const onRestart = async () => { setRestarting(true) try { await request.post('restart') } catch {} setRestarting(false) } return (
{(item) => (
)}
{t('urlForLatencyTest')} setUrlForLatencyTest(e.target.value)} />
{t('latencyTestTimeoutDuration')} ({t('ms')}) setLatencyTestTimeoutDuration(Number(e.target.value)) } />
{t('autoCloseConns')} setAutoCloseConns(e.target.checked)} />
) } const ConfigForXd = () => { const [t, { locale }] = useI18n() const navigate = useNavigate() const onSwitchEndpointClick = () => { setSelectedEndpoint('') navigate(ROUTES.Setup) } const autoSwitchThemeSubChild = () => (
{t('favDayTheme')}
{t('favNightTheme')}
) const checkboxList = [ { label: 'renderInTwoColumns', value: renderInTwoColumns, onChange: setRenderInTwoColumns, }, { label: 'renderRulesAndProviderInTwoColumns', value: renderRulesAndProviderInTwoColumns, onChange: setRenderRulesAndProviderInTwoColumns, }, { label: 'autoSwitchTheme', value: autoSwitchTheme, onChange: (value: boolean) => { setAutoSwitchTheme(value) applyThemeByMode() }, subChild: autoSwitchThemeSubChild, }, { label: 'useTwemoji', value: useTwemoji, onChange: setTwemoji, }, ] return (
{(checkbox) => ( <>
{t(checkbox.label)} { checkbox.onChange(e.target.checked) }} />
{checkbox.subChild?.()} )}
{t('proxiesPreviewType')}
{t('proxiesSorting')}
{t('tableSize')}
) } export default () => { return (
{import.meta.env.version}
) }