From d43c6b1ffc5e6c895f9e9f9de6625f17a9755c20 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Jan 2021 14:13:23 +0100 Subject: Implement remote interaction --- .../remote-interaction-routing.module.ts | 23 +++++++++ .../remote-interaction.component.html | 7 +++ .../remote-interaction.component.scss | 2 + .../remote-interaction.component.ts | 56 ++++++++++++++++++++++ .../remote-interaction.module.ts | 26 ++++++++++ .../comment/video-comment-add.component.html | 8 +--- client/src/app/app-routing.module.ts | 6 ++- client/src/app/core/routing/redirect.service.ts | 4 +- .../app/shared/form-validators/user-validators.ts | 11 +++++ .../remote-subscribe.component.html | 6 +-- .../remote-subscribe.component.ts | 37 ++++++++------ .../subscribe-button.component.html | 2 +- server/controllers/webfinger.ts | 5 ++ server/tests/misc-endpoints.ts | 25 ++++++++++ 14 files changed, 189 insertions(+), 29 deletions(-) create mode 100644 client/src/app/+remote-interaction/remote-interaction-routing.module.ts create mode 100644 client/src/app/+remote-interaction/remote-interaction.component.html create mode 100644 client/src/app/+remote-interaction/remote-interaction.component.scss create mode 100644 client/src/app/+remote-interaction/remote-interaction.component.ts create mode 100644 client/src/app/+remote-interaction/remote-interaction.module.ts diff --git a/client/src/app/+remote-interaction/remote-interaction-routing.module.ts b/client/src/app/+remote-interaction/remote-interaction-routing.module.ts new file mode 100644 index 000000000..1dddfb3ba --- /dev/null +++ b/client/src/app/+remote-interaction/remote-interaction-routing.module.ts @@ -0,0 +1,23 @@ +import { NgModule } from '@angular/core' +import { RouterModule, Routes } from '@angular/router' +import { LoginGuard } from '@app/core' +import { RemoteInteractionComponent } from './remote-interaction.component' + +const remoteInteractionRoutes: Routes = [ + { + path: '', + component: RemoteInteractionComponent, + canActivate: [ LoginGuard ], + data: { + meta: { + title: $localize`Remote interaction` + } + } + } +] + +@NgModule({ + imports: [ RouterModule.forChild(remoteInteractionRoutes) ], + exports: [ RouterModule ] +}) +export class RemoteInteractionRoutingModule {} diff --git a/client/src/app/+remote-interaction/remote-interaction.component.html b/client/src/app/+remote-interaction/remote-interaction.component.html new file mode 100644 index 000000000..e59783b9a --- /dev/null +++ b/client/src/app/+remote-interaction/remote-interaction.component.html @@ -0,0 +1,7 @@ +
+ +
+ {{ error }} +
+ +
diff --git a/client/src/app/+remote-interaction/remote-interaction.component.scss b/client/src/app/+remote-interaction/remote-interaction.component.scss new file mode 100644 index 000000000..5e6774739 --- /dev/null +++ b/client/src/app/+remote-interaction/remote-interaction.component.scss @@ -0,0 +1,2 @@ +@import '_variables'; +@import '_mixins'; diff --git a/client/src/app/+remote-interaction/remote-interaction.component.ts b/client/src/app/+remote-interaction/remote-interaction.component.ts new file mode 100644 index 000000000..e24607b24 --- /dev/null +++ b/client/src/app/+remote-interaction/remote-interaction.component.ts @@ -0,0 +1,56 @@ +import { forkJoin } from 'rxjs' +import { Component, OnInit } from '@angular/core' +import { ActivatedRoute, Router } from '@angular/router' +import { VideoChannel } from '@app/shared/shared-main' +import { SearchService } from '@app/shared/shared-search' + +@Component({ + selector: 'my-remote-interaction', + templateUrl: './remote-interaction.component.html', + styleUrls: ['./remote-interaction.component.scss'] +}) +export class RemoteInteractionComponent implements OnInit { + error = '' + + constructor ( + private route: ActivatedRoute, + private router: Router, + private search: SearchService + ) { } + + ngOnInit () { + const uri = this.route.snapshot.queryParams['uri'] + + if (!uri) { + this.error = $localize`URL parameter is missing in URL parameters` + return + } + + this.loadUrl(uri) + } + + private loadUrl (uri: string) { + forkJoin([ + this.search.searchVideos({ search: uri }), + this.search.searchVideoChannels({ search: uri }) + ]).subscribe(([ videoResult, channelResult ]) => { + let redirectUrl: string + + if (videoResult.data.length !== 0) { + const video = videoResult.data[0] + + redirectUrl = '/videos/watch/' + video.uuid + } else if (channelResult.data.length !== 0) { + const channel = new VideoChannel(channelResult.data[0]) + + redirectUrl = '/video-channels/' + channel.nameWithHost + } else { + this.error = $localize`Cannot access to the remote resource` + return + } + + this.router.navigateByUrl(redirectUrl) + }) + } + +} diff --git a/client/src/app/+remote-interaction/remote-interaction.module.ts b/client/src/app/+remote-interaction/remote-interaction.module.ts new file mode 100644 index 000000000..9f9f1cdfd --- /dev/null +++ b/client/src/app/+remote-interaction/remote-interaction.module.ts @@ -0,0 +1,26 @@ +import { CommonModule } from '@angular/common' +import { NgModule } from '@angular/core' +import { SharedSearchModule } from '@app/shared/shared-search' +import { RemoteInteractionRoutingModule } from './remote-interaction-routing.module' +import { RemoteInteractionComponent } from './remote-interaction.component' + +@NgModule({ + imports: [ + CommonModule, + + SharedSearchModule, + + RemoteInteractionRoutingModule + ], + + declarations: [ + RemoteInteractionComponent + ], + + exports: [ + RemoteInteractionComponent + ], + + providers: [] +}) +export class RemoteInteractionModule { } diff --git a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html index ca9cd863b..fdefed09a 100644 --- a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html +++ b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html @@ -57,13 +57,9 @@