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