mirror of https://github.com/Chocobozzz/PeerTube
Add WebFinger support (#1498)
* Add WebFinger support * Fix TS7006 * Follow lint * Fix TS7006pull/1535/head
parent
1b04f19c48
commit
583cd0d212
|
@ -37,7 +37,24 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit {
|
||||||
|
|
||||||
formValidated () {
|
formValidated () {
|
||||||
const address = this.form.value['text']
|
const address = this.form.value['text']
|
||||||
const [ , hostname ] = address.split('@')
|
const [ username, hostname ] = address.split('@')
|
||||||
window.open(`https://${hostname}/authorize_interaction?acct=${this.account}`)
|
|
||||||
|
fetch(`https://${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => new Promise((resolve, reject) => {
|
||||||
|
if (data && Array.isArray(data.links)) {
|
||||||
|
const link: {
|
||||||
|
template: string
|
||||||
|
} = data.links.find((link: any) =>
|
||||||
|
link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe')
|
||||||
|
|
||||||
|
if (link && link.template.includes('{uri}')) {
|
||||||
|
resolve(link.template.replace('{uri}', `acct:${this.account}`))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reject()
|
||||||
|
}))
|
||||||
|
.then(window.open)
|
||||||
|
.catch(() => window.open(`https://${hostname}/authorize_interaction?acct=${this.account}`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue