]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+remote-interaction/remote-interaction.component.ts
Update translations
[github/Chocobozzz/PeerTube.git] / client / src / app / +remote-interaction / remote-interaction.component.ts
1 import { forkJoin } from 'rxjs'
2 import { Component, OnInit } from '@angular/core'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { Video, VideoChannel } from '@app/shared/shared-main'
5 import { SearchService } from '@app/shared/shared-search'
6
7 @Component({
8 selector: 'my-remote-interaction',
9 templateUrl: './remote-interaction.component.html',
10 styleUrls: [ './remote-interaction.component.scss' ]
11 })
12 export class RemoteInteractionComponent implements OnInit {
13 error = ''
14
15 constructor (
16 private route: ActivatedRoute,
17 private router: Router,
18 private search: SearchService
19 ) { }
20
21 ngOnInit () {
22 const uri = this.route.snapshot.queryParams['uri']
23
24 if (!uri) {
25 this.error = $localize`URL parameter is missing in URL parameters`
26 return
27 }
28
29 this.loadUrl(uri)
30 }
31
32 private loadUrl (uri: string) {
33 forkJoin([
34 this.search.searchVideos({ search: uri }),
35 this.search.searchVideoChannels({ search: uri })
36 ]).subscribe(([ videoResult, channelResult ]) => {
37 let redirectUrl: string
38
39 if (videoResult.data.length !== 0) {
40 const video = videoResult.data[0]
41
42 redirectUrl = Video.buildWatchUrl(video)
43 } else if (channelResult.data.length !== 0) {
44 const channel = new VideoChannel(channelResult.data[0])
45
46 redirectUrl = '/c/' + channel.nameWithHost
47 } else {
48 this.error = $localize`Cannot access to the remote resource`
49 return
50 }
51
52 this.router.navigateByUrl(redirectUrl)
53 })
54 }
55
56 }