]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
c6c0fa6c 1import { forkJoin, of } from 'rxjs'
67ed6552 2import { map, switchMap } from 'rxjs/operators'
308c4275 3import { Injectable } from '@angular/core'
52798aa5 4import { ActivatedRouteSnapshot } from '@angular/router'
dc2b2938 5import { AuthService } from '@app/core'
d0800f76 6import { listUserChannelsForSelect } from '@app/helpers'
dc2b2938 7import { VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main'
f8c00564 8import { LiveVideoService } from '@app/shared/shared-video-live'
308c4275
C
9
10@Injectable()
52798aa5 11export class VideoUpdateResolver {
308c4275
C
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))),
2e401e85 26 map(([ video, videoSource, videoChannels, videoCaptions, liveVideo ]) =>
27 ({ video, videoChannels, videoCaptions, videoSource, liveVideo }))
c6c0fa6c
C
28 )
29 }
d0dba1fc 30
c6c0fa6c
C
31 private buildVideoObservables (video: VideoDetails) {
32 return [
33 this.videoService
34 .loadCompleteDescription(video.descriptionPath)
35 .pipe(map(description => Object.assign(video, { description }))),
d0dba1fc 36
2e401e85 37 this.videoService.getSource(video.id),
38
d0800f76 39 listUserChannelsForSelect(this.authService),
c6c0fa6c
C
40
41 this.videoCaptionService
7c07259a 42 .listCaptions(video.uuid)
c6c0fa6c
C
43 .pipe(
44 map(result => result.data)
45 ),
46
47 video.isLive
9df52d66
C
48 ? this.liveVideoService.getVideoLive(video.id)
49 : of(undefined)
c6c0fa6c 50 ]
308c4275
C
51 }
52}