]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-edit/video-add-components/video-send.ts
Support audio files import
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-add-components / video-send.ts
CommitLineData
78848714 1import { EventEmitter, OnInit } from '@angular/core'
43620009 2import { LoadingBarService } from '@ngx-loading-bar/core'
f8b2c1b4 3import { AuthService, Notifier, ServerService } from '@app/core'
78848714
C
4import { catchError, switchMap, tap } from 'rxjs/operators'
5import { FormReactive } from '@app/shared'
ba430d75 6import { ServerConfig, VideoConstant, VideoPrivacy } from '../../../../../../shared'
43620009 7import { VideoService } from '@app/shared/video/video.service'
78848714 8import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
43620009 9import { VideoCaptionService } from '@app/shared/video-caption'
43620009 10import { VideoEdit } from '@app/shared/video/video-edit.model'
78848714 11import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
c199c427 12import { CanComponentDeactivateResult } from '@app/shared/guards/can-deactivate-guard.service'
43620009 13
c199c427 14export abstract class VideoSend extends FormReactive implements OnInit {
43620009 15 userVideoChannels: { id: number, label: string, support: string }[] = []
8cd7faaa 16 videoPrivacies: VideoConstant<VideoPrivacy>[] = []
43620009
C
17 videoCaptions: VideoCaptionEdit[] = []
18
19 firstStepPrivacyId = 0
20 firstStepChannelId = 0
21
78848714 22 abstract firstStepDone: EventEmitter<string>
7373507f 23 abstract firstStepError: EventEmitter<void>
43620009
C
24 protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
25
26 protected loadingBar: LoadingBarService
f8b2c1b4 27 protected notifier: Notifier
43620009
C
28 protected authService: AuthService
29 protected serverService: ServerService
30 protected videoService: VideoService
31 protected videoCaptionService: VideoCaptionService
ba430d75 32 protected serverConfig: ServerConfig
43620009 33
c199c427 34 abstract canDeactivate (): CanComponentDeactivateResult
43620009
C
35
36 ngOnInit () {
37 this.buildForm({})
38
39 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
40 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
41
ba430d75
C
42 this.serverConfig = this.serverService.getTmpConfig()
43 this.serverService.getConfig()
44 .subscribe(config => this.serverConfig = config)
45
46 this.serverService.getVideoPrivacies()
43620009 47 .subscribe(
ba430d75
C
48 privacies => {
49 this.videoPrivacies = privacies
43620009
C
50
51 this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
52 })
53 }
54
55 checkForm () {
56 this.forceCheck()
57
58 return this.form.valid
59 }
60
61 protected updateVideoAndCaptions (video: VideoEdit) {
62 this.loadingBar.start()
63
64 return this.videoService.updateVideo(video)
65 .pipe(
66 // Then update captions
67 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
68 tap(() => this.loadingBar.complete()),
69 catchError(err => {
70 this.loadingBar.complete()
71 throw err
72 })
73 )
74 }
75}