aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts')
-rw-r--r--client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts16
1 files changed, 10 insertions, 6 deletions
diff --git a/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts b/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts
index 666199523..a951134eb 100644
--- a/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts
+++ b/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts
@@ -6,7 +6,7 @@ import { USER_HANDLE_VALIDATOR } from '../form-validators/user-validators'
6@Component({ 6@Component({
7 selector: 'my-remote-subscribe', 7 selector: 'my-remote-subscribe',
8 templateUrl: './remote-subscribe.component.html', 8 templateUrl: './remote-subscribe.component.html',
9 styleUrls: ['./remote-subscribe.component.scss'] 9 styleUrls: [ './remote-subscribe.component.scss' ]
10}) 10})
11export class RemoteSubscribeComponent extends FormReactive implements OnInit { 11export class RemoteSubscribeComponent extends FormReactive implements OnInit {
12 @Input() uri: string 12 @Input() uri: string
@@ -42,17 +42,21 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit {
42 // Should not have CORS error because https://tools.ietf.org/html/rfc7033#section-5 42 // Should not have CORS error because https://tools.ietf.org/html/rfc7033#section-5
43 fetch(`${protocol}//${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`) 43 fetch(`${protocol}//${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`)
44 .then(response => response.json()) 44 .then(response => response.json())
45 .then(data => new Promise((res, rej) => { 45 .then(data => {
46 if (!data || Array.isArray(data.links) === false) return rej() 46 if (!data || Array.isArray(data.links) === false) {
47 throw new Error('Not links in webfinger response')
48 }
47 49
48 const link: { template: string } = data.links.find((link: any) => { 50 const link: { template: string } = data.links.find((link: any) => {
49 return link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe' 51 return link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe'
50 }) 52 })
51 53
52 if (link && link.template.includes('{uri}')) { 54 if (link?.template.includes('{uri}')) {
53 res(link.template.replace('{uri}', encodeURIComponent(this.uri))) 55 return link.template.replace('{uri}', encodeURIComponent(this.uri))
54 } 56 }
55 })) 57
58 throw new Error('No subscribe template in webfinger response')
59 })
56 .then(window.open) 60 .then(window.open)
57 .catch(err => { 61 .catch(err => {
58 console.error(err) 62 console.error(err)