import { createForm } from '@felte/solid' import { validator } from '@felte/validator-zod' import { useI18n } from '@solid-primitives/i18n' import { For, Show, createSignal, onMount } from 'solid-js' import { z } from 'zod' import { Button } from '~/components' import { PROXIES_ORDERING_TYPE, PROXIES_PREVIEW_TYPE, themes, } from '~/constants' import { applyThemeByMode, autoCloseConns, autoSwitchTheme, favDayTheme, favNightTheme, proxiesOrderingType, proxiesPreviewType, renderInTwoColumn, setAutoCloseConns, setAutoSwitchTheme, setFavDayTheme, setFavNightTheme, setProxiesOrderingType, setProxiesPreviewType, setRenderInTwoColumn, setUrlForDelayTest, urlForDelayTest, useRequest, } from '~/signals' import type { DNSQuery, Config as IConfig } 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: 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 [upgraging, setUpgraging] = createSignal(false) const [restarting, setRestarting] = createSignal(false) const onUpdateGEODatabases = async () => { setUpdatingGEODatabases(true) try { await request.post('configs/geo') } catch {} setUpdatingGEODatabases(false) } const onUpgrade = async () => { setUpgraging(true) try { await request.post('upgrade') } catch {} setUpgraging(false) } const onRestart = async () => { setRestarting(true) try { await request.post('restart') } catch {} setRestarting(false) } return (
{(item) => (
)}
) } const ConfigForXd = () => { const [t] = useI18n() return (
{t('renderInTwoColumns')}
{ setRenderInTwoColumn(e.target.checked) }} />
{t('autoSwitchTheme')}
{ setAutoSwitchTheme(e.target.checked) applyThemeByMode() }} />
{t('favDayTheme')}
{t('favNightTheme')}
{t('proxiesPreviewType')}
{(value) => ( )}
{t('proxiesSorting')}
{(value) => ( )}
{t('autoCloseConns')}
setAutoCloseConns(e.target.checked)} />
{t('urlForDelayTest')}
setUrlForDelayTest(e.target?.value!)} />
) } export default () => { return (
) }