mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-10 17:25:34 +08:00
feat: try defalut host and secret && adapt openclash
This commit is contained in:
parent
9149a56300
commit
fa612a12d3
@ -4,7 +4,7 @@ import { useI18n } from '@solid-primitives/i18n'
|
|||||||
import { useNavigate } from '@solidjs/router'
|
import { useNavigate } from '@solidjs/router'
|
||||||
import { IconX } from '@tabler/icons-solidjs'
|
import { IconX } from '@tabler/icons-solidjs'
|
||||||
import ky from 'ky'
|
import ky from 'ky'
|
||||||
import { For } from 'solid-js'
|
import { For, onMount } from 'solid-js'
|
||||||
import { v4 as uuid } from 'uuid'
|
import { v4 as uuid } from 'uuid'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { endpointList, setEndpointList, setSelectedEndpoint } from '~/signals'
|
import { endpointList, setEndpointList, setSelectedEndpoint } from '~/signals'
|
||||||
@ -49,17 +49,16 @@ export default () => {
|
|||||||
onSetupSuccess(id)
|
onSetupSuccess(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { form } = createForm<z.infer<typeof schema>>({
|
const onSubmit = async ({ url, secret }: { url: string; secret: string }) => {
|
||||||
extend: validator({ schema }),
|
const list = endpointList().slice()
|
||||||
async onSubmit({ url, secret }) {
|
const point = list.find((history) => history.url === url)
|
||||||
const i = endpointList().findIndex((history) => history.url === url)
|
|
||||||
|
|
||||||
if (i > -1) {
|
if (point) {
|
||||||
const { id, secret: oldSecret } = endpointList()[i]
|
const { id, secret: oldSecret } = point
|
||||||
|
|
||||||
if (secret !== oldSecret && !(await checkEndpoint(url, secret))) {
|
if (secret !== oldSecret && !(await checkEndpoint(url, secret))) {
|
||||||
endpointList()[i].secret = secret
|
point.secret = secret
|
||||||
setEndpointList(endpointList())
|
setEndpointList(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
onSetupSuccess(id)
|
onSetupSuccess(id)
|
||||||
@ -71,14 +70,35 @@ export default () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const id = uuid()
|
const id = uuid()
|
||||||
setEndpointList([{ id, url, secret }, ...endpointList()])
|
setEndpointList([{ id, url, secret }, ...list])
|
||||||
onSetupSuccess(id)
|
onSetupSuccess(id)
|
||||||
},
|
}
|
||||||
|
|
||||||
|
const { form } = createForm<z.infer<typeof schema>>({
|
||||||
|
extend: validator({ schema }),
|
||||||
|
onSubmit: onSubmit,
|
||||||
})
|
})
|
||||||
|
|
||||||
const onRemove = (id: string) =>
|
const onRemove = (id: string) =>
|
||||||
setEndpointList(endpointList().filter((e) => e.id !== id))
|
setEndpointList(endpointList().filter((e) => e.id !== id))
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
const query = new URLSearchParams(window.location.search)
|
||||||
|
|
||||||
|
if (query.has('hostname')) {
|
||||||
|
onSubmit({
|
||||||
|
url: `http://${query.get('hostname')}${
|
||||||
|
query.get('port') && ':' + query.get('port')
|
||||||
|
}`,
|
||||||
|
secret: query.get('secret') ?? '',
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
onSubmit({
|
||||||
|
url: 'http://127.0.0.1:9090',
|
||||||
|
secret: '',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
return (
|
return (
|
||||||
<div class="mx-auto flex flex-col items-center gap-4 py-10 sm:w-2/3">
|
<div class="mx-auto flex flex-col items-center gap-4 py-10 sm:w-2/3">
|
||||||
<form class="contents" use:form={form}>
|
<form class="contents" use:form={form}>
|
||||||
@ -87,7 +107,7 @@ export default () => {
|
|||||||
name="url"
|
name="url"
|
||||||
type="url"
|
type="url"
|
||||||
class="input input-bordered"
|
class="input input-bordered"
|
||||||
placeholder="http://127.0.0.1:9090"
|
placeholder="host url"
|
||||||
list="defaultEndpoints"
|
list="defaultEndpoints"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user