1 import { Component, Input, OnInit } from '@angular/core'
2 import { FormReactive } from '@app/shared/forms/form-reactive'
6 } from '@app/shared/forms/form-validators'
9 selector: 'my-remote-subscribe',
10 templateUrl: './remote-subscribe.component.html',
11 styleUrls: ['./remote-subscribe.component.scss']
13 export class RemoteSubscribeComponent extends FormReactive implements OnInit {
15 @Input() interact = false
16 @Input() showHelp = false
19 protected formValidatorService: FormValidatorService,
20 private userValidatorsService: UserValidatorsService
27 text: this.userValidatorsService.USER_EMAIL
33 if (!this.form.valid) return
39 const address = this.form.value['text']
40 const [ username, hostname ] = address.split('@')
42 // Should not have CORS error because https://tools.ietf.org/html/rfc7033#section-5
43 fetch(`https://${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`)
44 .then(response => response.json())
45 .then(data => new Promise((resolve, reject) => {
48 if (data && Array.isArray(data.links)) {
49 const link: { template: string } = data.links.find((link: any) => {
50 return link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe'
53 if (link && link.template.includes('{uri}')) {
54 resolve(link.template.replace('{uri}', encodeURIComponent(this.uri)))
60 .catch(err => console.error(err))