PeerTube/client/src/app/+videos/+video-edit/video-add-components/video-send.ts

74 lines
2.5 KiB
TypeScript
Raw Normal View History

2020-06-23 14:10:17 +02:00
import { catchError, switchMap, tap } from 'rxjs/operators'
2020-08-06 16:14:58 +02:00
import { Directive, EventEmitter, OnInit } from '@angular/core'
2020-06-23 14:10:17 +02:00
import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
import { populateAsyncUserVideoChannels } from '@app/helpers'
import { FormReactive } from '@app/shared/shared-forms'
import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
2018-08-06 15:12:54 +02:00
import { LoadingBarService } from '@ngx-loading-bar/core'
2020-06-23 14:10:17 +02:00
import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
2018-08-06 15:12:54 +02:00
2020-06-26 08:37:26 +02:00
@Directive()
2020-08-06 16:14:58 +02:00
// tslint:disable-next-line: directive-class-suffix
2018-10-18 14:35:31 +02:00
export abstract class VideoSend extends FormReactive implements OnInit {
2018-08-06 15:12:54 +02:00
userVideoChannels: { id: number, label: string, support: string }[] = []
2018-09-04 16:21:07 +02:00
videoPrivacies: VideoConstant<VideoPrivacy>[] = []
2018-08-06 15:12:54 +02:00
videoCaptions: VideoCaptionEdit[] = []
firstStepPrivacyId = 0
firstStepChannelId = 0
abstract firstStepDone: EventEmitter<string>
2018-11-16 10:05:25 +01:00
abstract firstStepError: EventEmitter<void>
2018-08-06 15:12:54 +02:00
protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
protected loadingBar: LoadingBarService
protected notifier: Notifier
2018-08-06 15:12:54 +02:00
protected authService: AuthService
protected serverService: ServerService
protected videoService: VideoService
protected videoCaptionService: VideoCaptionService
2019-12-18 15:31:54 +01:00
protected serverConfig: ServerConfig
2018-08-06 15:12:54 +02:00
2018-10-18 14:35:31 +02:00
abstract canDeactivate (): CanComponentDeactivateResult
2018-08-06 15:12:54 +02:00
ngOnInit () {
this.buildForm({})
populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
.then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
2019-12-18 15:31:54 +01:00
this.serverConfig = this.serverService.getTmpConfig()
this.serverService.getConfig()
.subscribe(config => this.serverConfig = config)
this.serverService.getVideoPrivacies()
2018-08-06 15:12:54 +02:00
.subscribe(
2019-12-18 15:31:54 +01:00
privacies => {
this.videoPrivacies = privacies
2018-08-06 15:12:54 +02:00
this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
})
}
checkForm () {
this.forceCheck()
return this.form.valid
}
protected updateVideoAndCaptions (video: VideoEdit) {
2020-08-06 16:14:58 +02:00
this.loadingBar.useRef().start()
2018-08-06 15:12:54 +02:00
return this.videoService.updateVideo(video)
.pipe(
// Then update captions
switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
2020-08-06 16:14:58 +02:00
tap(() => this.loadingBar.useRef().complete()),
2018-08-06 15:12:54 +02:00
catchError(err => {
2020-08-06 16:14:58 +02:00
this.loadingBar.useRef().complete()
2018-08-06 15:12:54 +02:00
throw err
})
)
}
}