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'
8 export class VideoUpdateResolver implements Resolve<any> {
10 private videoService: VideoService,
11 private liveVideoService: LiveVideoService,
12 private videoChannelService: VideoChannelService,
13 private videoCaptionService: VideoCaptionService
17 resolve (route: ActivatedRouteSnapshot) {
18 const uuid: string = route.params[ 'uuid' ]
20 return this.videoService.getVideo({ videoId: uuid })
22 switchMap(video => forkJoin(this.buildVideoObservables(video))),
23 map(([ video, videoChannels, videoCaptions, videoLive ]) => ({ video, videoChannels, videoCaptions, videoLive }))
27 private buildVideoObservables (video: VideoDetails) {
30 .loadCompleteDescription(video.descriptionPath)
31 .pipe(map(description => Object.assign(video, { description }))),
33 this.videoChannelService
34 .listAccountVideoChannels(video.account)
36 map(result => result.data),
37 map(videoChannels => videoChannels.map(c => ({
41 avatarPath: c.avatar?.path
45 this.videoCaptionService
46 .listCaptions(video.id)
48 map(result => result.data)
52 ? this.liveVideoService.getVideoLive(video.id)