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 { AuthService } from '@app/core'
6 import { listUserChannelsForSelect } from '@app/helpers'
7 import { VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main'
8 import { LiveVideoService } from '@app/shared/shared-video-live'
11 export class VideoUpdateResolver implements Resolve<any> {
13 private videoService: VideoService,
14 private liveVideoService: LiveVideoService,
15 private authService: AuthService,
16 private videoCaptionService: VideoCaptionService
20 resolve (route: ActivatedRouteSnapshot) {
21 const uuid: string = route.params['uuid']
23 return this.videoService.getVideo({ videoId: uuid })
25 switchMap(video => forkJoin(this.buildVideoObservables(video))),
26 map(([ video, videoSource, videoChannels, videoCaptions, liveVideo ]) =>
27 ({ video, videoChannels, videoCaptions, videoSource, liveVideo }))
31 private buildVideoObservables (video: VideoDetails) {
34 .loadCompleteDescription(video.descriptionPath)
35 .pipe(map(description => Object.assign(video, { description }))),
37 this.videoService.getSource(video.id),
39 listUserChannelsForSelect(this.authService),
41 this.videoCaptionService
42 .listCaptions(video.uuid)
44 map(result => result.data)
48 ? this.liveVideoService.getVideoLive(video.id)