refactor: shorten checkEndpoint

This commit is contained in:
kunish 2023-08-30 18:01:48 +08:00
parent 0e54e396d1
commit 1cffb4b305
No known key found for this signature in database
GPG Key ID: 647A12B4F782C430

View File

@ -21,27 +21,17 @@ export default () => {
navigate('/overview')
}
const checkEndpoint = async ({
url,
secret,
}: {
url: string
secret: string
}) => {
try {
const { ok } = await ky.get(url, {
const checkEndpoint = ({ url, secret }: { url: string; secret: string }) =>
ky
.get(url, {
headers: secret
? {
Authorization: `Bearer ${secret}`,
}
: {},
})
return ok
} catch {
return false
}
}
.then(({ ok }) => ok)
.catch(() => false)
const onEndpointSelect = async (id: string) => {
const endpoint = endpointList().find((e) => e.id === id)