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