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