]>
Commit | Line | Data |
---|---|---|
5fb2e288 C |
1 | import { map } from 'rxjs/operators' |
2 | import { Injectable } from '@angular/core' | |
3 | import { ActivatedRouteSnapshot, Resolve, Router } from '@angular/router' | |
1942f11d | 4 | import { SearchService } from '@app/shared/shared-search' |
5fb2e288 C |
5 | |
6 | @Injectable() | |
7 | export class VideoLazyLoadResolver implements Resolve<any> { | |
8 | constructor ( | |
9 | private router: Router, | |
10 | private searchService: SearchService | |
11 | ) { } | |
12 | ||
13 | resolve (route: ActivatedRouteSnapshot) { | |
14 | const url = route.params.url | |
5fb2e288 C |
15 | |
16 | if (!url) { | |
17 | console.error('Could not find url param.', { params: route.params }) | |
18 | return this.router.navigateByUrl('/404') | |
19 | } | |
20 | ||
5fb2e288 C |
21 | return this.searchService.searchVideos({ search: url }) |
22 | .pipe( | |
23 | map(result => { | |
24 | if (result.data.length !== 1) { | |
25 | console.error('Cannot find result for this URL') | |
26 | return this.router.navigateByUrl('/404') | |
27 | } | |
28 | ||
29 | const video = result.data[0] | |
30 | ||
31 | return this.router.navigateByUrl('/videos/watch/' + video.uuid) | |
32 | }) | |
33 | ) | |
34 | } | |
35 | } |