]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-edit/video-update.resolver.ts
Add client hooks
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-update.resolver.ts
1 import { Injectable } from '@angular/core'
2 import { VideoService } from '@app/shared/video/video.service'
3 import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
4 import { map, switchMap } from 'rxjs/operators'
5 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
6 import { VideoCaptionService } from '@app/shared/video-caption'
7 import { forkJoin } from 'rxjs'
8
9 @Injectable()
10 export class VideoUpdateResolver implements Resolve<any> {
11 constructor (
12 private videoService: VideoService,
13 private videoChannelService: VideoChannelService,
14 private videoCaptionService: VideoCaptionService
15 ) {
16 }
17
18 resolve (route: ActivatedRouteSnapshot) {
19 const uuid: string = route.params[ 'uuid' ]
20
21 return this.videoService.getVideo({ videoId: uuid })
22 .pipe(
23 switchMap(video => {
24 return forkJoin([
25 this.videoService
26 .loadCompleteDescription(video.descriptionPath)
27 .pipe(map(description => Object.assign(video, { description }))),
28
29 this.videoChannelService
30 .listAccountVideoChannels(video.account)
31 .pipe(
32 map(result => result.data),
33 map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName, support: c.support })))
34 ),
35
36 this.videoCaptionService
37 .listCaptions(video.id)
38 .pipe(
39 map(result => result.data)
40 )
41 ])
42 }),
43 map(([ video, videoChannels, videoCaptions ]) => ({ video, videoChannels, videoCaptions }))
44 )
45 }
46 }