]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/video-update.resolver.ts
Update changelog
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-update.resolver.ts
CommitLineData
c6c0fa6c 1import { forkJoin, of } from 'rxjs'
67ed6552 2import { map, switchMap } from 'rxjs/operators'
308c4275 3import { Injectable } from '@angular/core'
308c4275 4import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
dc2b2938
C
5import { AuthService } from '@app/core'
6import { listUserChannels } from '@app/helpers'
7import { VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main'
f8c00564 8import { LiveVideoService } from '@app/shared/shared-video-live'
308c4275
C
9
10@Injectable()
11export class VideoUpdateResolver implements Resolve<any> {
12 constructor (
13 private videoService: VideoService,
a5cf76af 14 private liveVideoService: LiveVideoService,
dc2b2938 15 private authService: AuthService,
308c4275 16 private videoCaptionService: VideoCaptionService
d0dba1fc
C
17 ) {
18 }
308c4275
C
19
20 resolve (route: ActivatedRouteSnapshot) {
9df52d66 21 const uuid: string = route.params['uuid']
308c4275 22
93cae479 23 return this.videoService.getVideo({ videoId: uuid })
d0dba1fc 24 .pipe(
c6c0fa6c 25 switchMap(video => forkJoin(this.buildVideoObservables(video))),
b5b68755 26 map(([ video, videoChannels, videoCaptions, liveVideo ]) => ({ video, videoChannels, videoCaptions, liveVideo }))
c6c0fa6c
C
27 )
28 }
d0dba1fc 29
c6c0fa6c
C
30 private buildVideoObservables (video: VideoDetails) {
31 return [
32 this.videoService
33 .loadCompleteDescription(video.descriptionPath)
34 .pipe(map(description => Object.assign(video, { description }))),
d0dba1fc 35
dc2b2938 36 listUserChannels(this.authService),
c6c0fa6c
C
37
38 this.videoCaptionService
39 .listCaptions(video.id)
40 .pipe(
41 map(result => result.data)
42 ),
43
44 video.isLive
9df52d66
C
45 ? this.liveVideoService.getVideoLive(video.id)
46 : of(undefined)
c6c0fa6c 47 ]
308c4275
C
48 }
49}