1 import { map } from 'rxjs/operators'
2 import { Injectable } from '@angular/core'
3 import { ActivatedRouteSnapshot, Resolve, Router } from '@angular/router'
4 import { SearchService } from './search.service'
5 import { RedirectService } from '@app/core'
8 export class ChannelLazyLoadResolver implements Resolve<any> {
10 private router: Router,
11 private searchService: SearchService,
12 private redirectService: RedirectService
15 resolve (route: ActivatedRouteSnapshot) {
16 const url = route.params.url
17 const externalRedirect = route.params.externalRedirect
18 const fromPath = route.params.fromPath
21 console.error('Could not find url param.', { params: route.params })
22 return this.router.navigateByUrl('/404')
25 if (externalRedirect === 'true') {
27 this.router.navigateByUrl(fromPath)
31 return this.searchService.searchVideoChannels({ search: url })
34 if (result.data.length !== 1) {
35 console.error('Cannot find result for this URL')
36 return this.router.navigateByUrl('/404')
39 const channel = result.data[0]
41 return this.router.navigateByUrl('/video-channels/' + channel.nameWithHost)