aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-edit/video-update.resolver.ts
blob: 269fe3684497f62b505d61ac071942a0da9e3c0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Injectable } from '@angular/core'
import { VideoService } from '@app/shared/video/video.service'
import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
import { map, switchMap } from 'rxjs/operators'
import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
import { VideoCaptionService } from '@app/shared/video-caption'

@Injectable()
export class VideoUpdateResolver implements Resolve<any> {
  constructor (
    private videoService: VideoService,
    private videoChannelService: VideoChannelService,
    private videoCaptionService: VideoCaptionService
  ) {}

  resolve (route: ActivatedRouteSnapshot) {
    const uuid: string = route.params[ 'uuid' ]

    return this.videoService.getVideo(uuid)
        .pipe(
          switchMap(video => {
            return this.videoService
                       .loadCompleteDescription(video.descriptionPath)
                       .pipe(map(description => Object.assign(video, { description })))
          }),
          switchMap(video => {
            return this.videoChannelService
                       .listAccountVideoChannels(video.account)
                       .pipe(
                         map(result => result.data),
                         map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName, support: c.support }))),
                         map(videoChannels => ({ video, videoChannels }))
                       )
          }),
          switchMap(({ video, videoChannels }) => {
            return this.videoCaptionService
                       .listCaptions(video.id)
                       .pipe(
                         map(result => result.data),
                         map(videoCaptions => ({ video, videoChannels, videoCaptions }))
                       )
          })
        )
  }
}