mirror of
https://github.com/tooot-app/app
synced 2025-03-12 09:30:11 +01:00
Fix #719
This commit is contained in:
parent
1df73b070a
commit
63900c4338
@ -9,13 +9,22 @@ export type QueryKeyInstance = ['Instance'] | ['Instance', { domain?: string }]
|
||||
|
||||
const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyInstance>) => {
|
||||
const domain = queryKey[1]?.domain
|
||||
|
||||
const checkV2Format = (body: Mastodon.Instance_V2) => {
|
||||
if (body.version) {
|
||||
return body
|
||||
} else {
|
||||
throw new Error('Instance v2 format error')
|
||||
}
|
||||
}
|
||||
|
||||
if (domain) {
|
||||
return await apiGeneral<Mastodon.Instance<'v2'>>({
|
||||
method: 'get',
|
||||
domain,
|
||||
url: 'api/v2/instance'
|
||||
})
|
||||
.then(res => res.body)
|
||||
.then(res => checkV2Format(res.body))
|
||||
.catch(
|
||||
async () =>
|
||||
await apiGeneral<Mastodon.Instance<'v1'>>({
|
||||
@ -32,7 +41,7 @@ const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyInstance
|
||||
version: 'v2',
|
||||
url: 'instance'
|
||||
})
|
||||
.then(res => res.body)
|
||||
.then(res => checkV2Format(res.body))
|
||||
.catch(
|
||||
async () =>
|
||||
await apiInstance<Mastodon.Instance<'v1'>>({
|
||||
|
Loading…
x
Reference in New Issue
Block a user