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 ++++++++++ 5 files changed, 114 insertions(+) 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 (limited to 'client/src/app/+remote-interaction') 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 { } -- cgit v1.2.3