2020-09-17 07:20:52 +00:00
|
|
|
import { forkJoin, of } from 'rxjs'
|
2020-06-23 12:10:17 +00:00
|
|
|
import { map, switchMap } from 'rxjs/operators'
|
2018-07-16 16:09:31 +00:00
|
|
|
import { Injectable } from '@angular/core'
|
|
|
|
import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
|
2021-05-10 07:31:33 +00:00
|
|
|
import { AuthService } from '@app/core'
|
|
|
|
import { listUserChannels } from '@app/helpers'
|
|
|
|
import { VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main'
|
2020-11-05 09:56:23 +00:00
|
|
|
import { LiveVideoService } from '@app/shared/shared-video-live'
|
2018-07-16 16:09:31 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class VideoUpdateResolver implements Resolve<any> {
|
|
|
|
constructor (
|
|
|
|
private videoService: VideoService,
|
2020-09-25 08:04:21 +00:00
|
|
|
private liveVideoService: LiveVideoService,
|
2021-05-10 07:31:33 +00:00
|
|
|
private authService: AuthService,
|
2018-07-16 16:09:31 +00:00
|
|
|
private videoCaptionService: VideoCaptionService
|
2019-04-25 08:51:52 +00:00
|
|
|
) {
|
|
|
|
}
|
2018-07-16 16:09:31 +00:00
|
|
|
|
|
|
|
resolve (route: ActivatedRouteSnapshot) {
|
|
|
|
const uuid: string = route.params[ 'uuid' ]
|
|
|
|
|
2019-07-22 13:40:13 +00:00
|
|
|
return this.videoService.getVideo({ videoId: uuid })
|
2019-04-25 08:51:52 +00:00
|
|
|
.pipe(
|
2020-09-17 07:20:52 +00:00
|
|
|
switchMap(video => forkJoin(this.buildVideoObservables(video))),
|
2020-10-26 15:44:23 +00:00
|
|
|
map(([ video, videoChannels, videoCaptions, liveVideo ]) => ({ video, videoChannels, videoCaptions, liveVideo }))
|
2020-09-17 07:20:52 +00:00
|
|
|
)
|
|
|
|
}
|
2019-04-25 08:51:52 +00:00
|
|
|
|
2020-09-17 07:20:52 +00:00
|
|
|
private buildVideoObservables (video: VideoDetails) {
|
|
|
|
return [
|
|
|
|
this.videoService
|
|
|
|
.loadCompleteDescription(video.descriptionPath)
|
|
|
|
.pipe(map(description => Object.assign(video, { description }))),
|
2019-04-25 08:51:52 +00:00
|
|
|
|
2021-05-10 07:31:33 +00:00
|
|
|
listUserChannels(this.authService),
|
2020-09-17 07:20:52 +00:00
|
|
|
|
|
|
|
this.videoCaptionService
|
|
|
|
.listCaptions(video.id)
|
|
|
|
.pipe(
|
|
|
|
map(result => result.data)
|
|
|
|
),
|
|
|
|
|
|
|
|
video.isLive
|
2020-09-25 08:04:21 +00:00
|
|
|
? this.liveVideoService.getVideoLive(video.id)
|
2020-09-17 07:20:52 +00:00
|
|
|
: of(undefined)
|
|
|
|
]
|
2018-07-16 16:09:31 +00:00
|
|
|
}
|
|
|
|
}
|