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') navigate('/overview')
} }
const checkEndpoint = async ({ const checkEndpoint = ({ url, secret }: { url: string; secret: string }) =>
url, ky
secret, .get(url, {
}: {
url: string
secret: string
}) => {
try {
const { ok } = await ky.get(url, {
headers: secret headers: secret
? { ? {
Authorization: `Bearer ${secret}`, Authorization: `Bearer ${secret}`,
} }
: {}, : {},
}) })
.then(({ ok }) => ok)
return ok .catch(() => false)
} catch {
return false
}
}
const onEndpointSelect = async (id: string) => { const onEndpointSelect = async (id: string) => {
const endpoint = endpointList().find((e) => e.id === id) const endpoint = endpointList().find((e) => e.id === id)