]>
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 { VideoCaptionService, VideoChannelService, VideoDetails, LiveVideoService, VideoService } from '@app/shared/shared-main' | |
6 | ||
7 | @Injectable() | |
8 | export class VideoUpdateResolver implements Resolve<any> { | |
9 | constructor ( | |
10 | private videoService: VideoService, | |
11 | private liveVideoService: LiveVideoService, | |
12 | private videoChannelService: VideoChannelService, | |
13 | private videoCaptionService: VideoCaptionService | |
14 | ) { | |
15 | } | |
16 | ||
17 | resolve (route: ActivatedRouteSnapshot) { | |
18 | const uuid: string = route.params[ 'uuid' ] | |
19 | ||
20 | return this.videoService.getVideo({ videoId: uuid }) | |
21 | .pipe( | |
22 | switchMap(video => forkJoin(this.buildVideoObservables(video))), | |
23 | map(([ video, videoChannels, videoCaptions, liveVideo ]) => ({ video, videoChannels, videoCaptions, liveVideo })) | |
24 | ) | |
25 | } | |
26 | ||
27 | private buildVideoObservables (video: VideoDetails) { | |
28 | return [ | |
29 | this.videoService | |
30 | .loadCompleteDescription(video.descriptionPath) | |
31 | .pipe(map(description => Object.assign(video, { description }))), | |
32 | ||
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 | |
52 | ? this.liveVideoService.getVideoLive(video.id) | |
53 | : of(undefined) | |
54 | ] | |
55 | } | |
56 | } |