From 457b49827dd38b61e63fd73e90a3736c956b4157 Mon Sep 17 00:00:00 2001 From: Zephyruso <127948745+Zephyruso@users.noreply.github.com> Date: Mon, 28 Aug 2023 22:13:48 +0800 Subject: [PATCH] feat: rules page (#10) --- src/pages/Config.tsx | 75 ++++++++++++++++++++++++++++++++++++++- src/pages/Connections.tsx | 7 ++-- src/pages/Rules.tsx | 61 ++++++++++++++++++++++++++++++- src/pages/Setup.tsx | 2 +- src/types.d.ts | 7 ++++ 5 files changed, 147 insertions(+), 5 deletions(-) diff --git a/src/pages/Config.tsx b/src/pages/Config.tsx index beb5921..1bc5a4d 100644 --- a/src/pages/Config.tsx +++ b/src/pages/Config.tsx @@ -1,3 +1,76 @@ +import { useRequest } from '~/signals' +import { For, onMount } from 'solid-js' +import type { Config as IConfig } from '~/types' +import { z } from 'zod' +import { validator } from '@felte/validator-zod' +import { createForm } from '@felte/solid' + +const schema = z.object({ + port: z.number(), + 'socks-port': z.number(), + 'redir-port': z.number(), + 'tproxy-port': z.number(), + 'mixed-port': z.number(), +}) + export const Config = () => { - return
config
+ const request = useRequest() + const formItemList = [ + { + key: 'port', + label: 'port', + type: 'number', + }, + { + key: 'socks-port', + label: 'socks-port', + type: 'number', + }, + { + key: 'redir-port', + label: 'redir-port', + type: 'number', + }, + { + key: 'tproxy-port', + label: 'tproxy-port', + type: 'number', + }, + { + key: 'mixed-port', + label: 'mixed-port', + type: 'number', + }, + ] + + const { form, setInitialValues, reset } = createForm>({ + extend: validator({ schema }), + }) + onMount(async () => { + const configs = await request.get('configs').json() + + setInitialValues(configs) + reset() + }) + + return ( +
+ config +
+ + {(item) => ( +
+ {item.label}: + +
+ )} +
+
+
+ ) } diff --git a/src/pages/Connections.tsx b/src/pages/Connections.tsx index ef66f65..003c7b3 100644 --- a/src/pages/Connections.tsx +++ b/src/pages/Connections.tsx @@ -46,7 +46,11 @@ export const Connections = () => { const onCloseConnection = (id: string) => request.delete(`connections/${id}`) - const [sorting, setSorting] = createSignal([]) + const defaultSorting = Object.freeze({ + id: 'ID', + desc: true, + }) + const [sorting, setSorting] = createSignal([defaultSorting]) const columns: ColumnDef[] = [ { @@ -182,7 +186,6 @@ export const Connections = () => { header.column.columnDef.header, header.getContext(), )} - {{ asc: , desc: , diff --git a/src/pages/Rules.tsx b/src/pages/Rules.tsx index dbbc904..fe83dd0 100644 --- a/src/pages/Rules.tsx +++ b/src/pages/Rules.tsx @@ -1,3 +1,62 @@ +import { For, createSignal, onMount } from 'solid-js' +import { useRequest } from '~/signals' +import type { Rule, RuleProvider } from '~/types' + export const Rules = () => { - return
rules
+ const request = useRequest() + const [rules, setRules] = createSignal([]) + const [rulesProviders, setRulesProviders] = createSignal([]) + + onMount(async () => { + const { rules } = await request + .get('rules') + .json<{ rules: Record }>() + + setRules(Object.values(rules)) + + const { providers } = await request + .get('providers/rules') + .json<{ providers: Record }>() + + setRulesProviders(Object.values(providers)) + }) + + return ( +
+
+

Rules

+ +
+ + {(rule) => ( +
+
{rule.payload}
+
+ {rule.type}: {rule.proxy} +
+
+ )} +
+
+
+ +
+

Rules Providers

+ +
+ + {(rulesProvider) => ( +
+
{rulesProvider.name}
+
+ {rulesProvider.vehicleType}: {rulesProvider.behavior} ( + {rulesProvider.ruleCount}) +
+
+ )} +
+
+
+
+ ) } diff --git a/src/pages/Setup.tsx b/src/pages/Setup.tsx index 70489cb..902bfcc 100644 --- a/src/pages/Setup.tsx +++ b/src/pages/Setup.tsx @@ -37,7 +37,7 @@ export const Setup = () => { { id: uuid(), url: values.url, - secret: '', + secret: values.secret, }, ...endpointList(), ]) diff --git a/src/types.d.ts b/src/types.d.ts index 3e50fe3..bcff54c 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -42,6 +42,13 @@ export type ProxyProvider = { vehicleType: string } +export type Rule = { + type: string + payload: string + proxy: string + size: number +} + export type RuleProvider = { behavior: string format: string