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'
|
2020-09-25 08:04:21 +00:00
|
|
|
import { VideoCaptionService, VideoChannelService, VideoDetails, LiveVideoService, VideoService } from '@app/shared/shared-main'
|
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,
|
2018-07-16 16:09:31 +00:00
|
|
|
private videoChannelService: VideoChannelService,
|
|
|
|
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))),
|
|
|
|
map(([ video, videoChannels, videoCaptions, videoLive ]) => ({ video, videoChannels, videoCaptions, videoLive }))
|
|
|
|
)
|
|
|
|
}
|
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
|
|
|
|
2020-09-17 07:20:52 +00:00
|
|
|
this.videoChannelService
|
|
|
|
.listAccountVideoChannels(video.account)
|
|
|
|
.pipe(
|
|
|
|
map(result => result.data),
|
|
|
|
map(videoChannels => videoChannels.map(c => ({
|
|
|
|
id: c.id,
|
|
|
|
label: c.displayName,
|
|
|
|
support: c.support,
|
|
|
|
avatarPath: c.avatar?.path
|
|
|
|
})))
|
|
|
|
),
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|