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