]>
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' |
a5cf76af | 5 | import { VideoCaptionService, VideoChannelService, VideoDetails, LiveVideoService, VideoService } from '@app/shared/shared-main' |
308c4275 C |
6 | |
7 | @Injectable() | |
8 | export class VideoUpdateResolver implements Resolve<any> { | |
9 | constructor ( | |
10 | private videoService: VideoService, | |
a5cf76af | 11 | private liveVideoService: LiveVideoService, |
308c4275 C |
12 | private videoChannelService: VideoChannelService, |
13 | private videoCaptionService: VideoCaptionService | |
d0dba1fc C |
14 | ) { |
15 | } | |
308c4275 C |
16 | |
17 | resolve (route: ActivatedRouteSnapshot) { | |
18 | const uuid: string = route.params[ 'uuid' ] | |
19 | ||
93cae479 | 20 | return this.videoService.getVideo({ videoId: uuid }) |
d0dba1fc | 21 | .pipe( |
c6c0fa6c C |
22 | switchMap(video => forkJoin(this.buildVideoObservables(video))), |
23 | map(([ video, videoChannels, videoCaptions, videoLive ]) => ({ video, videoChannels, videoCaptions, videoLive })) | |
24 | ) | |
25 | } | |
d0dba1fc | 26 | |
c6c0fa6c C |
27 | private buildVideoObservables (video: VideoDetails) { |
28 | return [ | |
29 | this.videoService | |
30 | .loadCompleteDescription(video.descriptionPath) | |
31 | .pipe(map(description => Object.assign(video, { description }))), | |
d0dba1fc | 32 | |
c6c0fa6c C |
33 | this.videoChannelService |
34 | .listAccountVideoChannels(video.account) | |
35 | .pipe( | |
36 | map(result => result.data), | |
37 | map(videoChannels => videoChannels.map(c => ({ | |
38 | id: c.id, | |
39 | label: c.displayName, | |
40 | support: c.support, | |
41 | avatarPath: c.avatar?.path | |
42 | }))) | |
43 | ), | |
44 | ||
45 | this.videoCaptionService | |
46 | .listCaptions(video.id) | |
47 | .pipe( | |
48 | map(result => result.data) | |
49 | ), | |
50 | ||
51 | video.isLive | |
a5cf76af | 52 | ? this.liveVideoService.getVideoLive(video.id) |
c6c0fa6c C |
53 | : of(undefined) |
54 | ] | |
308c4275 C |
55 | } |
56 | } |