aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search/channel-lazy-load.resolver.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-05-29 16:16:24 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-10 14:02:41 +0200
commit5fb2e2888ce032c638e4b75d07458642f0833e52 (patch)
tree8830d873569316889b8134027e9a43b198cca38f /client/src/app/search/channel-lazy-load.resolver.ts
parent62e7be634bc189f942ae51cb4b080079ab503ff0 (diff)
downloadPeerTube-5fb2e2888ce032c638e4b75d07458642f0833e52.tar.gz
PeerTube-5fb2e2888ce032c638e4b75d07458642f0833e52.tar.zst
PeerTube-5fb2e2888ce032c638e4b75d07458642f0833e52.zip
First implem global search
Diffstat (limited to 'client/src/app/search/channel-lazy-load.resolver.ts')
-rw-r--r--client/src/app/search/channel-lazy-load.resolver.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/client/src/app/search/channel-lazy-load.resolver.ts b/client/src/app/search/channel-lazy-load.resolver.ts
new file mode 100644
index 000000000..8be089cdd
--- /dev/null
+++ b/client/src/app/search/channel-lazy-load.resolver.ts
@@ -0,0 +1,45 @@
1import { map } from 'rxjs/operators'
2import { Injectable } from '@angular/core'
3import { ActivatedRouteSnapshot, Resolve, Router } from '@angular/router'
4import { SearchService } from './search.service'
5import { RedirectService } from '@app/core'
6
7@Injectable()
8export class ChannelLazyLoadResolver implements Resolve<any> {
9 constructor (
10 private router: Router,
11 private searchService: SearchService,
12 private redirectService: RedirectService
13 ) { }
14
15 resolve (route: ActivatedRouteSnapshot) {
16 const url = route.params.url
17 const externalRedirect = route.params.externalRedirect
18 const fromPath = route.params.fromPath
19
20 if (!url) {
21 console.error('Could not find url param.', { params: route.params })
22 return this.router.navigateByUrl('/404')
23 }
24
25 if (externalRedirect === 'true') {
26 window.open(url)
27 this.router.navigateByUrl(fromPath)
28 return
29 }
30
31 return this.searchService.searchVideoChannels({ search: url })
32 .pipe(
33 map(result => {
34 if (result.data.length !== 1) {
35 console.error('Cannot find result for this URL')
36 return this.router.navigateByUrl('/404')
37 }
38
39 const channel = result.data[0]
40
41 return this.router.navigateByUrl('/video-channels/' + channel.nameWithHost)
42 })
43 )
44 }
45}