aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-01-14 14:13:23 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-01-15 10:49:10 +0100
commitd43c6b1ffc5e6c895f9e9f9de6625f17a9755c20 (patch)
tree6bdcbe9893574e0b5a41c4854c7f986f346ba761 /client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts
parentb0a9743af0273835cdf594431a774c0f7d46b539 (diff)
downloadPeerTube-d43c6b1ffc5e6c895f9e9f9de6625f17a9755c20.tar.gz
PeerTube-d43c6b1ffc5e6c895f9e9f9de6625f17a9755c20.tar.zst
PeerTube-d43c6b1ffc5e6c895f9e9f9de6625f17a9755c20.zip
Implement remote interaction
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.ts37
1 files changed, 22 insertions, 15 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 b46c91bf8..666199523 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
@@ -1,6 +1,7 @@
1import { Component, Input, OnInit } from '@angular/core' 1import { Component, Input, OnInit } from '@angular/core'
2import { Notifier } from '@app/core'
2import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' 3import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
3import { USER_EMAIL_VALIDATOR } from '../form-validators/user-validators' 4import { USER_HANDLE_VALIDATOR } from '../form-validators/user-validators'
4 5
5@Component({ 6@Component({
6 selector: 'my-remote-subscribe', 7 selector: 'my-remote-subscribe',
@@ -13,14 +14,15 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit {
13 @Input() showHelp = false 14 @Input() showHelp = false
14 15
15 constructor ( 16 constructor (
16 protected formValidatorService: FormValidatorService 17 protected formValidatorService: FormValidatorService,
18 private notifier: Notifier
17 ) { 19 ) {
18 super() 20 super()
19 } 21 }
20 22
21 ngOnInit () { 23 ngOnInit () {
22 this.buildForm({ 24 this.buildForm({
23 text: USER_EMAIL_VALIDATOR 25 text: USER_HANDLE_VALIDATOR
24 }) 26 })
25 } 27 }
26 28
@@ -35,22 +37,27 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit {
35 const address = this.form.value['text'] 37 const address = this.form.value['text']
36 const [ username, hostname ] = address.split('@') 38 const [ username, hostname ] = address.split('@')
37 39
40 const protocol = window.location.protocol
41
38 // 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
39 fetch(`https://${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`) 43 fetch(`${protocol}//${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`)
40 .then(response => response.json()) 44 .then(response => response.json())
41 .then(data => new Promise((resolve, reject) => { 45 .then(data => new Promise((res, rej) => {
42 if (data && Array.isArray(data.links)) { 46 if (!data || Array.isArray(data.links) === false) return rej()
43 const link: { template: string } = data.links.find((link: any) => { 47
44 return link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe' 48 const link: { template: string } = data.links.find((link: any) => {
45 }) 49 return link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe'
46 50 })
47 if (link && link.template.includes('{uri}')) { 51
48 resolve(link.template.replace('{uri}', encodeURIComponent(this.uri))) 52 if (link && link.template.includes('{uri}')) {
49 } 53 res(link.template.replace('{uri}', encodeURIComponent(this.uri)))
50 } 54 }
51 reject()
52 })) 55 }))
53 .then(window.open) 56 .then(window.open)
54 .catch(err => console.error(err)) 57 .catch(err => {
58 console.error(err)
59
60 this.notifier.error($localize`Cannot fetch information of this remote account`)
61 })
55 } 62 }
56} 63}