- uploadFirstStep () {
- const videofile = this.videofileInput.nativeElement.files[0]
- const name = videofile.name.replace(/\.[^/.]+$/, '')
- const privacy = this.firstStepPrivacyId.toString()
- const nsfw = false
- const channelId = this.firstStepChannelId.toString()
-
- const formData = new FormData()
- formData.append('name', name)
- // Put the video "private" -> we wait he validates the second step
- formData.append('privacy', VideoPrivacy.PRIVATE.toString())
- formData.append('nsfw', '' + nsfw)
- formData.append('channelId', '' + channelId)
- formData.append('videofile', videofile)
-
- this.isUploadingVideo = true
- this.form.patchValue({
- name,
- privacy,
- nsfw,
- channelId
- })
-
- this.videoService.uploadVideo(formData).subscribe(
- event => {
- if (event.type === HttpEventType.UploadProgress) {
- this.videoUploadPercents = Math.round(100 * event.loaded / event.total)
- } else if (event instanceof HttpResponse) {
- console.log('Video uploaded.')
-
- this.videoUploaded = true
-
- this.videoUploadedId = event.body.video.id
- }
- },
-
- err => {
- // Reset progress
- this.videoUploadPercents = 0
- this.error = err.message
- }
- )
- }
-
- updateSecondStep () {
- if (this.checkForm() === false) {
- return
- }
-
- const video = new VideoEdit()
- video.patch(this.form.value)
- video.channel = this.firstStepChannelId
- video.id = this.videoUploadedId
-
- this.videoService.updateVideo(video)
- .subscribe(
- () => {
- this.notificationsService.success('Success', 'Video published.')
- this.router.navigate([ '/videos/watch', video.id ])
- },
-
- err => {
- this.error = 'Cannot update the video.'
- console.error(err)
- }
- )
-