diff options
Diffstat (limited to 'client/src/app/+remote-interaction/remote-interaction.component.ts')
-rw-r--r-- | client/src/app/+remote-interaction/remote-interaction.component.ts | 56 |
1 files changed, 56 insertions, 0 deletions
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 @@ | |||
1 | import { forkJoin } from 'rxjs' | ||
2 | import { Component, OnInit } from '@angular/core' | ||
3 | import { ActivatedRoute, Router } from '@angular/router' | ||
4 | import { 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 = '/videos/watch/' + video.uuid | ||
43 | } else if (channelResult.data.length !== 0) { | ||
44 | const channel = new VideoChannel(channelResult.data[0]) | ||
45 | |||
46 | redirectUrl = '/video-channels/' + 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 | } | ||