]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts
Registration css fixes
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-user-subscription / remote-subscribe.component.ts
index 66619952343be7296788178fbbe8d879f0b34ad7..36969271530da72394ee8e52931bab9a2cf43ded 100644 (file)
@@ -6,7 +6,7 @@ import { USER_HANDLE_VALIDATOR } from '../form-validators/user-validators'
 @Component({
   selector: 'my-remote-subscribe',
   templateUrl: './remote-subscribe.component.html',
-  styleUrls: ['./remote-subscribe.component.scss']
+  styleUrls: [ './remote-subscribe.component.scss' ]
 })
 export class RemoteSubscribeComponent extends FormReactive implements OnInit {
   @Input() uri: string
@@ -27,7 +27,7 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit {
   }
 
   onValidKey () {
-    this.check()
+    this.forceCheck()
     if (!this.form.valid) return
 
     this.formValidated()
@@ -42,17 +42,21 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit {
     // Should not have CORS error because https://tools.ietf.org/html/rfc7033#section-5
     fetch(`${protocol}//${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`)
       .then(response => response.json())
-      .then(data => new Promise((res, rej) => {
-        if (!data || Array.isArray(data.links) === false) return rej()
+      .then(data => {
+        if (!data || Array.isArray(data.links) === false) {
+          throw new Error('Not links in webfinger response')
+        }
 
         const link: { template: string } = data.links.find((link: any) => {
           return link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe'
         })
 
-        if (link && link.template.includes('{uri}')) {
-          res(link.template.replace('{uri}', encodeURIComponent(this.uri)))
+        if (link?.template.includes('{uri}')) {
+          return link.template.replace('{uri}', encodeURIComponent(this.uri))
         }
-      }))
+
+        throw new Error('No subscribe template in webfinger response')
+      })
       .then(window.open)
       .catch(err => {
         console.error(err)