]>
Commit | Line | Data |
---|---|---|
1 | import { forkJoin, of } from 'rxjs' | |
2 | import { map, switchMap } from 'rxjs/operators' | |
3 | import { Injectable } from '@angular/core' | |
4 | import { ActivatedRouteSnapshot, Resolve } from '@angular/router' | |
5 | import { AuthService } from '@app/core' | |
6 | import { listUserChannels } from '@app/helpers' | |
7 | import { VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main' | |
8 | import { LiveVideoService } from '@app/shared/shared-video-live' | |
9 | ||
10 | @Injectable() | |
11 | export class VideoUpdateResolver implements Resolve<any> { | |
12 | constructor ( | |
13 | private videoService: VideoService, | |
14 | private liveVideoService: LiveVideoService, | |
15 | private authService: AuthService, | |
16 | private videoCaptionService: VideoCaptionService | |
17 | ) { | |
18 | } | |
19 | ||
20 | resolve (route: ActivatedRouteSnapshot) { | |
21 | const uuid: string = route.params['uuid'] | |
22 | ||
23 | return this.videoService.getVideo({ videoId: uuid }) | |
24 | .pipe( | |
25 | switchMap(video => forkJoin(this.buildVideoObservables(video))), | |
26 | map(([ video, videoChannels, videoCaptions, liveVideo ]) => ({ video, videoChannels, videoCaptions, liveVideo })) | |
27 | ) | |
28 | } | |
29 | ||
30 | private buildVideoObservables (video: VideoDetails) { | |
31 | return [ | |
32 | this.videoService | |
33 | .loadCompleteDescription(video.descriptionPath) | |
34 | .pipe(map(description => Object.assign(video, { description }))), | |
35 | ||
36 | listUserChannels(this.authService), | |
37 | ||
38 | this.videoCaptionService | |
39 | .listCaptions(video.id) | |
40 | .pipe( | |
41 | map(result => result.data) | |
42 | ), | |
43 | ||
44 | video.isLive | |
45 | ? this.liveVideoService.getVideoLive(video.id) | |
46 | : of(undefined) | |
47 | ] | |
48 | } | |
49 | } |