mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-24 09:45:35 +08:00
fix: setup onsubmit secret
This commit is contained in:
parent
880a40f18e
commit
30fd13946b
@ -8,7 +8,12 @@ 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 { Button } from '~/components'
|
import { Button } from '~/components'
|
||||||
import { endpointList, setEndpointList, setSelectedEndpoint } from '~/signals'
|
import {
|
||||||
|
endpointList,
|
||||||
|
selectedEndpoint,
|
||||||
|
setEndpointList,
|
||||||
|
setSelectedEndpoint,
|
||||||
|
} from '~/signals'
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
url: z.string().url().nonempty(),
|
url: z.string().url().nonempty(),
|
||||||
@ -51,28 +56,27 @@ export default () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onSubmit = async ({ url, secret }: { url: string; secret: string }) => {
|
const onSubmit = async ({ url, secret }: { url: string; secret: string }) => {
|
||||||
const list = endpointList().slice()
|
|
||||||
const point = list.find((history) => history.url === url)
|
|
||||||
|
|
||||||
if (point) {
|
|
||||||
const { id, secret: oldSecret } = point
|
|
||||||
|
|
||||||
if (secret !== oldSecret && !(await checkEndpoint(url, secret))) {
|
|
||||||
point.secret = secret
|
|
||||||
setEndpointList(list)
|
|
||||||
}
|
|
||||||
|
|
||||||
onSetupSuccess(id)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(await checkEndpoint(url, secret))) {
|
if (!(await checkEndpoint(url, secret))) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = uuid()
|
const id = uuid()
|
||||||
setEndpointList([{ id, url, secret }, ...list])
|
const list = endpointList().slice()
|
||||||
|
const point = list.find((history) => history.url === url)
|
||||||
|
|
||||||
|
if (!point) {
|
||||||
|
// new host and secret
|
||||||
|
setEndpointList([{ id, url, secret }, ...list])
|
||||||
|
onSetupSuccess(id)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// exist host we update secret and id no matter secret is equal or not
|
||||||
|
point.secret = secret
|
||||||
|
point.id = id
|
||||||
|
|
||||||
|
setEndpointList(list)
|
||||||
onSetupSuccess(id)
|
onSetupSuccess(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,8 +85,13 @@ export default () => {
|
|||||||
onSubmit,
|
onSubmit,
|
||||||
})
|
})
|
||||||
|
|
||||||
const onRemove = (id: string) =>
|
const onRemove = (id: string) => {
|
||||||
|
if (selectedEndpoint() === id) {
|
||||||
|
setSelectedEndpoint('')
|
||||||
|
}
|
||||||
|
|
||||||
setEndpointList(endpointList().filter((e) => e.id !== id))
|
setEndpointList(endpointList().filter((e) => e.id !== id))
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const query = new URLSearchParams(window.location.search)
|
const query = new URLSearchParams(window.location.search)
|
||||||
@ -94,11 +103,6 @@ export default () => {
|
|||||||
}`,
|
}`,
|
||||||
secret: query.get('secret') ?? '',
|
secret: query.get('secret') ?? '',
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
void onSubmit({
|
|
||||||
url: 'http://127.0.0.1:9090',
|
|
||||||
secret: '',
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user