]>
Commit | Line | Data |
---|---|---|
308c4275 C |
1 | import { Injectable } from '@angular/core' |
2 | import { VideoService } from '@app/shared/video/video.service' | |
3 | import { ActivatedRouteSnapshot, Resolve } from '@angular/router' | |
4 | import { map, switchMap } from 'rxjs/operators' | |
5 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | |
6 | import { VideoCaptionService } from '@app/shared/video-caption' | |
7 | ||
8 | @Injectable() | |
9 | export class VideoUpdateResolver implements Resolve<any> { | |
10 | constructor ( | |
11 | private videoService: VideoService, | |
12 | private videoChannelService: VideoChannelService, | |
13 | private videoCaptionService: VideoCaptionService | |
14 | ) {} | |
15 | ||
16 | resolve (route: ActivatedRouteSnapshot) { | |
17 | const uuid: string = route.params[ 'uuid' ] | |
18 | ||
19 | return this.videoService.getVideo(uuid) | |
20 | .pipe( | |
21 | switchMap(video => { | |
22 | return this.videoService | |
23 | .loadCompleteDescription(video.descriptionPath) | |
24 | .pipe(map(description => Object.assign(video, { description }))) | |
25 | }), | |
26 | switchMap(video => { | |
27 | return this.videoChannelService | |
28 | .listAccountVideoChannels(video.account) | |
29 | .pipe( | |
30 | map(result => result.data), | |
31 | map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName, support: c.support }))), | |
32 | map(videoChannels => ({ video, videoChannels })) | |
33 | ) | |
34 | }), | |
35 | switchMap(({ video, videoChannels }) => { | |
36 | return this.videoCaptionService | |
37 | .listCaptions(video.id) | |
38 | .pipe( | |
39 | map(result => result.data), | |
40 | map(videoCaptions => ({ video, videoChannels, videoCaptions })) | |
41 | ) | |
42 | }) | |
43 | ) | |
44 | } | |
45 | } |