feat: update secret when changed (#48)

Co-authored-by: kunish <17328586+kunish@users.noreply.github.com>
This commit is contained in:
PuerNya 2023-08-31 13:43:21 +08:00 committed by GitHub
parent 21e2b29159
commit 935908e0c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,13 +50,17 @@ export default () => {
const { form } = createForm<z.infer<typeof schema>>({
extend: validator({ schema }),
async onSubmit({ url, secret }) {
const endpointFromHistory = endpointList().find(
(history) => history.url === url && history.secret === secret,
)
const i = endpointList().findIndex((history) => history.url === url)
if (endpointFromHistory) {
onSetupSuccess(endpointFromHistory.id)
if (i > -1) {
const { id, secret: oldSecret } = endpointList()[i]
if (secret !== oldSecret && !(await checkEndpoint(url, secret))) {
endpointList()[i].secret = secret
setEndpointList(endpointList())
}
onSetupSuccess(id)
return
}