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

50 lines
1.6 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'
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,
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) {
2021-08-17 12:42:53 +00:00
const uuid: string = route.params['uuid']
2018-07-16 16:09:31 +00:00
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))),
2020-10-26 15:44:23 +00:00
map(([ video, videoChannels, videoCaptions, liveVideo ]) => ({ video, videoChannels, videoCaptions, liveVideo }))
)
}
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
2021-05-10 07:31:33 +00:00
listUserChannels(this.authService),
this.videoCaptionService
.listCaptions(video.id)
.pipe(
map(result => result.data)
),
video.isLive
2021-08-17 12:42:53 +00:00
? this.liveVideoService.getVideoLive(video.id)
: of(undefined)
]
2018-07-16 16:09:31 +00:00
}
}