import { HttpEventType, HttpResponse } from '@angular/common/http'
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
-import { FormBuilder, FormGroup } from '@angular/forms'
import { Router } from '@angular/router'
import { UserService } from '@app/shared'
import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
import { NotificationsService } from 'angular2-notifications'
import { BytesPipe } from 'ngx-pipes'
import { Subscription } from 'rxjs'
-import { VideoPrivacy } from '../../../../../shared/models/videos'
+import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos'
import { AuthService, ServerService } from '../../core'
import { FormReactive } from '../../shared'
-import { ValidatorMessage } from '../../shared/forms/form-validators/validator-message'
import { populateAsyncUserVideoChannels } from '../../shared/misc/utils'
import { VideoEdit } from '../../shared/video/video-edit.model'
import { VideoService } from '../../shared/video/video.service'
import { I18n } from '@ngx-translate/i18n-polyfill'
+import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
+import { switchMap } from 'rxjs/operators'
+import { VideoCaptionService } from '@app/shared/video-caption'
+import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
@Component({
selector: 'my-videos-add',
export class VideoAddComponent extends FormReactive implements OnInit, OnDestroy, CanComponentDeactivate {
@ViewChild('videofileInput') videofileInput
+ // So that it can be accessed in the template
+ readonly SPECIAL_SCHEDULED_PRIVACY = VideoEdit.SPECIAL_SCHEDULED_PRIVACY
+
isUploadingVideo = false
isUpdatingVideo = false
videoUploaded = false
}
videoFileName: string
- form: FormGroup
- formErrors: { [ id: string ]: string } = {}
- validationMessages: ValidatorMessage = {}
-
userVideoChannels: { id: number, label: string, support: string }[] = []
userVideoQuotaUsed = 0
- videoPrivacies = []
+ videoPrivacies: VideoConstant<string>[] = []
firstStepPrivacyId = 0
firstStepChannelId = 0
+ videoCaptions: VideoCaptionEdit[] = []
constructor (
- private formBuilder: FormBuilder,
+ protected formValidatorService: FormValidatorService,
private router: Router,
private notificationsService: NotificationsService,
private authService: AuthService,
private serverService: ServerService,
private videoService: VideoService,
private loadingBar: LoadingBarService,
- private i18n: I18n
+ private i18n: I18n,
+ private videoCaptionService: VideoCaptionService
) {
super()
}
return this.serverService.getConfig().video.file.extensions.join(',')
}
- buildForm () {
- this.form = this.formBuilder.group({})
- this.form.valueChanges.subscribe(data => this.onValueChanged(data))
- }
-
ngOnInit () {
- this.buildForm()
+ this.buildForm({})
populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
.then(() => this.firstStepChannelId = this.userVideoChannels[0].id)
const videofile = this.videofileInput.nativeElement.files[0] as File
if (!videofile) return
- // Cannot upload videos > 4GB for now
- if (videofile.size > 4 * 1024 * 1024 * 1024) {
- this.notificationsService.error(this.i18n('Error'), this.i18n('We are sorry but PeerTube cannot handle videos > 4GB'))
+ // Cannot upload videos > 8GB for now
+ if (videofile.size > 8 * 1024 * 1024 * 1024) {
+ this.notificationsService.error(this.i18n('Error'), this.i18n('We are sorry but PeerTube cannot handle videos > 8GB'))
return
}
let name: string
// If the name of the file is very small, keep the extension
- if (nameWithoutExtension.length < 3) {
- name = videofile.name
- } else {
- name = nameWithoutExtension
- }
+ if (nameWithoutExtension.length < 3) name = videofile.name
+ else name = nameWithoutExtension
const privacy = this.firstStepPrivacyId.toString()
const nsfw = false
+ const waitTranscoding = true
const commentsEnabled = true
const channelId = this.firstStepChannelId.toString()
formData.append('privacy', VideoPrivacy.PRIVATE.toString())
formData.append('nsfw', '' + nsfw)
formData.append('commentsEnabled', '' + commentsEnabled)
+ formData.append('waitTranscoding', '' + waitTranscoding)
formData.append('channelId', '' + channelId)
formData.append('videofile', videofile)
this.isUpdatingVideo = true
this.loadingBar.start()
this.videoService.updateVideo(video)
- .subscribe(
- () => {
- this.isUpdatingVideo = false
- this.isUploadingVideo = false
- this.loadingBar.complete()
-
- this.notificationsService.success(this.i18n('Success'), this.i18n('Video published.'))
- this.router.navigate([ '/videos/watch', video.uuid ])
- },
-
- err => {
- this.isUpdatingVideo = false
- this.notificationsService.error(this.i18n('Error'), err.message)
- console.error(err)
- }
- )
-
+ .pipe(
+ // Then update captions
+ switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions))
+ )
+ .subscribe(
+ () => {
+ this.isUpdatingVideo = false
+ this.isUploadingVideo = false
+ this.loadingBar.complete()
+
+ this.notificationsService.success(this.i18n('Success'), this.i18n('Video published.'))
+ this.router.navigate([ '/videos/watch', video.uuid ])
+ },
+
+ err => {
+ this.isUpdatingVideo = false
+ this.notificationsService.error(this.i18n('Error'), err.message)
+ console.error(err)
+ }
+ )
}
}