2018-07-16 16:09:31 +00:00
|
|
|
import { Injectable } from '@angular/core'
|
|
|
|
import { VideoService } from '@app/shared/video/video.service'
|
|
|
|
import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
|
|
|
|
import { map, switchMap } from 'rxjs/operators'
|
|
|
|
import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
|
|
|
|
import { VideoCaptionService } from '@app/shared/video-caption'
|
2019-04-25 08:51:52 +00:00
|
|
|
import { forkJoin } from 'rxjs'
|
2018-07-16 16:09:31 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class VideoUpdateResolver implements Resolve<any> {
|
|
|
|
constructor (
|
|
|
|
private videoService: VideoService,
|
|
|
|
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' ]
|
|
|
|
|
|
|
|
return this.videoService.getVideo(uuid)
|
2019-04-25 08:51:52 +00:00
|
|
|
.pipe(
|
|
|
|
switchMap(video => {
|
|
|
|
return forkJoin([
|
|
|
|
this.videoService
|
|
|
|
.loadCompleteDescription(video.descriptionPath)
|
|
|
|
.pipe(map(description => Object.assign(video, { description }))),
|
|
|
|
|
|
|
|
this.videoChannelService
|
|
|
|
.listAccountVideoChannels(video.account)
|
|
|
|
.pipe(
|
|
|
|
map(result => result.data),
|
|
|
|
map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName, support: c.support })))
|
|
|
|
),
|
|
|
|
|
|
|
|
this.videoCaptionService
|
|
|
|
.listCaptions(video.id)
|
|
|
|
.pipe(
|
|
|
|
map(result => result.data)
|
|
|
|
)
|
|
|
|
])
|
|
|
|
}),
|
|
|
|
map(([ video, videoChannels, videoCaptions ]) => ({ video, videoChannels, videoCaptions }))
|
|
|
|
)
|
2018-07-16 16:09:31 +00:00
|
|
|
}
|
|
|
|
}
|