1
0
Fork 0
peertube/client/src/app/+videos/+video-edit/video-update.resolver.ts

57 lines
1.8 KiB
TypeScript
Raw Normal View History

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'
import { VideoCaptionService, VideoChannelService, VideoDetails, VideoLiveService, 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,
private videoLiveService: VideoLiveService,
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(
switchMap(video => forkJoin(this.buildVideoObservables(video))),
map(([ video, videoChannels, videoCaptions, videoLive ]) => ({ video, videoChannels, videoCaptions, videoLive }))
)
}
2019-04-25 08:51: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
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
? this.videoLiveService.getVideoLive(video.id)
: of(undefined)
]
2018-07-16 16:09:31 +00:00
}
}