mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-01-01 03:28:20 +01:00
refs #1028 Confirm ActivityPub instance to read host-meta before login
This commit is contained in:
parent
b2ca839a21
commit
dd4ca9432a
@ -46,9 +46,17 @@ const actions: ActionTree<LoginState, RootState> = {
|
||||
},
|
||||
confirmInstance: async ({ commit }, domain: string): Promise<boolean> => {
|
||||
commit(MUTATION_TYPES.CHANGE_SEARCHING, true)
|
||||
await axios.get(`https://${domain}/api/v1/instance`).finally(() => {
|
||||
// https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8
|
||||
// Check /.well-known/host-meta to confirm mastodon instance.
|
||||
const res = await axios.get(`https://${domain}/.well-known/host-meta`).finally(() => {
|
||||
commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
|
||||
})
|
||||
const parser = new DOMParser()
|
||||
const dom = parser.parseFromString(res.data, 'text/xml')
|
||||
const link = dom.getElementsByTagName('Link')[0].outerHTML
|
||||
if (!link.includes(`https://${domain}/.well-known/webfinger`)) {
|
||||
throw new Error('domain is not activity pub')
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_INSTANCE, domain)
|
||||
return true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user