X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-user-subscription%2Fremote-subscribe.component.ts;h=66619952343be7296788178fbbe8d879f0b34ad7;hb=c86fa51b8a84210f3b9fcbeebc3f03f280d5982d;hp=09164a5d3699827f62e2d428af3061dcf8b31e56;hpb=67ed6552b831df66713bac9e672738796128d33f;p=github%2FChocobozzz%2FPeerTube.git 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 09164a5d3..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,5 +1,7 @@ import { Component, Input, OnInit } from '@angular/core' -import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms' +import { Notifier } from '@app/core' +import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' +import { USER_HANDLE_VALIDATOR } from '../form-validators/user-validators' @Component({ selector: 'my-remote-subscribe', @@ -13,14 +15,14 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit { constructor ( protected formValidatorService: FormValidatorService, - private userValidatorsService: UserValidatorsService + private notifier: Notifier ) { super() } ngOnInit () { this.buildForm({ - text: this.userValidatorsService.USER_EMAIL + text: USER_HANDLE_VALIDATOR }) } @@ -35,24 +37,27 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit { const address = this.form.value['text'] const [ username, hostname ] = address.split('@') + const protocol = window.location.protocol + // Should not have CORS error because https://tools.ietf.org/html/rfc7033#section-5 - fetch(`https://${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`) + fetch(`${protocol}//${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`) .then(response => response.json()) - .then(data => new Promise((resolve, reject) => { - console.log(data) + .then(data => new Promise((res, rej) => { + if (!data || Array.isArray(data.links) === false) return rej() - if (data && Array.isArray(data.links)) { - const link: { template: string } = data.links.find((link: any) => { - return link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe' - }) + 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}')) { - resolve(link.template.replace('{uri}', encodeURIComponent(this.uri))) - } + if (link && link.template.includes('{uri}')) { + res(link.template.replace('{uri}', encodeURIComponent(this.uri))) } - reject() })) .then(window.open) - .catch(err => console.error(err)) + .catch(err => { + console.error(err) + + this.notifier.error($localize`Cannot fetch information of this remote account`) + }) } }