]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/user-subscription/remote-subscribe.component.ts
Handle overview pagination in client
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / user-subscription / remote-subscribe.component.ts
CommitLineData
660d11e9
RK
1import { Component, Input, OnInit } from '@angular/core'
2import { FormReactive } from '@app/shared/forms/form-reactive'
3import {
4 FormValidatorService,
5 UserValidatorsService
6} from '@app/shared/forms/form-validators'
7
8@Component({
9 selector: 'my-remote-subscribe',
10 templateUrl: './remote-subscribe.component.html',
11 styleUrls: ['./remote-subscribe.component.scss']
12})
13export class RemoteSubscribeComponent extends FormReactive implements OnInit {
3ddb1ec5 14 @Input() uri: string
660d11e9
RK
15 @Input() interact = false
16 @Input() showHelp = false
17
18 constructor (
19 protected formValidatorService: FormValidatorService,
20 private userValidatorsService: UserValidatorsService
21 ) {
22 super()
23 }
24
25 ngOnInit () {
26 this.buildForm({
27 text: this.userValidatorsService.USER_EMAIL
28 })
29 }
30
31 onValidKey () {
3866f1a0 32 this.check()
660d11e9
RK
33 if (!this.form.valid) return
34
35 this.formValidated()
36 }
37
38 formValidated () {
39 const address = this.form.value['text']
583cd0d2
AC
40 const [ username, hostname ] = address.split('@')
41
f0ad4710 42 // Should not have CORS error because https://tools.ietf.org/html/rfc7033#section-5
583cd0d2
AC
43 fetch(`https://${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`)
44 .then(response => response.json())
45 .then(data => new Promise((resolve, reject) => {
3ddb1ec5
C
46 console.log(data)
47
583cd0d2 48 if (data && Array.isArray(data.links)) {
3ddb1ec5
C
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'
51 })
583cd0d2
AC
52
53 if (link && link.template.includes('{uri}')) {
3ddb1ec5 54 resolve(link.template.replace('{uri}', encodeURIComponent(this.uri)))
583cd0d2
AC
55 }
56 }
57 reject()
58 }))
59 .then(window.open)
3ddb1ec5 60 .catch(err => console.error(err))
660d11e9
RK
61 }
62}