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