]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+remote-interaction/remote-interaction.component.ts
Fix upload avatar button
[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',
9 templateUrl: './remote-interaction.component.html',
9df52d66 10 styleUrls: [ './remote-interaction.component.scss' ]
d43c6b1f
C
11})
12export 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
d4a8e7a6 42 redirectUrl = Video.buildWatchUrl(video)
d43c6b1f
C
43 } else if (channelResult.data.length !== 0) {
44 const channel = new VideoChannel(channelResult.data[0])
45
71887396 46 redirectUrl = '/c/' + channel.nameWithHost
d43c6b1f
C
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}