]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/video-update.resolver.ts
Merge remote-tracking branch 'weblate/develop' into develop
[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'
f8c00564
C
5import { VideoCaptionService, VideoChannelService, VideoDetails, VideoService } from '@app/shared/shared-main'
6import { LiveVideoService } from '@app/shared/shared-video-live'
308c4275
C
7
8@Injectable()
9export class VideoUpdateResolver implements Resolve<any> {
10 constructor (
11 private videoService: VideoService,
a5cf76af 12 private liveVideoService: LiveVideoService,
308c4275
C
13 private videoChannelService: VideoChannelService,
14 private videoCaptionService: VideoCaptionService
d0dba1fc
C
15 ) {
16 }
308c4275
C
17
18 resolve (route: ActivatedRouteSnapshot) {
19 const uuid: string = route.params[ 'uuid' ]
20
93cae479 21 return this.videoService.getVideo({ videoId: uuid })
d0dba1fc 22 .pipe(
c6c0fa6c 23 switchMap(video => forkJoin(this.buildVideoObservables(video))),
b5b68755 24 map(([ video, videoChannels, videoCaptions, liveVideo ]) => ({ video, videoChannels, videoCaptions, liveVideo }))
c6c0fa6c
C
25 )
26 }
d0dba1fc 27
c6c0fa6c
C
28 private buildVideoObservables (video: VideoDetails) {
29 return [
30 this.videoService
31 .loadCompleteDescription(video.descriptionPath)
32 .pipe(map(description => Object.assign(video, { description }))),
d0dba1fc 33
c6c0fa6c
C
34 this.videoChannelService
35 .listAccountVideoChannels(video.account)
36 .pipe(
37 map(result => result.data),
38 map(videoChannels => videoChannels.map(c => ({
39 id: c.id,
40 label: c.displayName,
41 support: c.support,
42 avatarPath: c.avatar?.path
43 })))
44 ),
45
46 this.videoCaptionService
47 .listCaptions(video.id)
48 .pipe(
49 map(result => result.data)
50 ),
51
52 video.isLive
a5cf76af 53 ? this.liveVideoService.getVideoLive(video.id)
c6c0fa6c
C
54 : of(undefined)
55 ]
308c4275
C
56 }
57}