aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-edit/video-add-components
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-06 15:30:24 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 09:30:31 +0200
commit788487140c500abeb69ca44daf3a9e26efa8d36f (patch)
tree1870338bcd00848f9ab24067b8b9e545870723d0 /client/src/app/videos/+video-edit/video-add-components
parent047559af6e7570ac98b0d11ab43e60a9c5c1f5c3 (diff)
downloadPeerTube-788487140c500abeb69ca44daf3a9e26efa8d36f.tar.gz
PeerTube-788487140c500abeb69ca44daf3a9e26efa8d36f.tar.zst
PeerTube-788487140c500abeb69ca44daf3a9e26efa8d36f.zip
Move send video components inside a dedicated directory
Diffstat (limited to 'client/src/app/videos/+video-edit/video-add-components')
-rw-r--r--client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html60
-rw-r--r--client/src/app/videos/+video-edit/video-add-components/video-import-url.component.scss37
-rw-r--r--client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts132
-rw-r--r--client/src/app/videos/+video-edit/video-add-components/video-send.ts71
-rw-r--r--client/src/app/videos/+video-edit/video-add-components/video-upload.component.html58
-rw-r--r--client/src/app/videos/+video-edit/video-add-components/video-upload.component.scss85
-rw-r--r--client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts219
7 files changed, 662 insertions, 0 deletions
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html
new file mode 100644
index 000000000..6b431f6f6
--- /dev/null
+++ b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html
@@ -0,0 +1,60 @@
1<div *ngIf="!hasImportedVideo" class="upload-video-container">
2 <div class="import-video">
3 <div class="icon icon-upload"></div>
4
5 <div class="form-group">
6 <label i18n for="targetUrl">URL</label>
7 <my-help
8 helpType="custom" i18n-customHtml
9 customHtml="You can import any URL <a href='https://rg3.github.io/youtube-dl/supportedsites.html' target='_blank' rel='noopener noreferrer'>supported by youtube-dl</a> or URL that points to a raw MP4 file. You should make sure you have diffusion rights over the content it points to, otherwise it could cause legal trouble to yourself and your instance."
10 ></my-help>
11
12 <input type="text" id="targetUrl" [(ngModel)]="targetUrl" />
13 </div>
14
15 <div class="form-group">
16 <label i18n for="first-step-channel">Channel</label>
17 <div class="peertube-select-container">
18 <select id="first-step-channel" [(ngModel)]="firstStepChannelId">
19 <option *ngFor="let channel of userVideoChannels" [value]="channel.id">{{ channel.label }}</option>
20 </select>
21 </div>
22 </div>
23
24 <div class="form-group">
25 <label i18n for="first-step-privacy">Privacy</label>
26 <div class="peertube-select-container">
27 <select id="first-step-privacy" [(ngModel)]="firstStepPrivacyId">
28 <option *ngFor="let privacy of videoPrivacies" [value]="privacy.id">{{ privacy.label }}</option>
29 </select>
30 </div>
31 </div>
32
33 <input
34 type="button" i18n-value value="Import"
35 [disabled]="!isTargetUrlValid() || isImportingVideo" (click)="importVideo()"
36 />
37 </div>
38</div>
39
40<div *ngIf="hasImportedVideo" class="alert alert-info" i18n>
41 Congratulations, the video behind {{ targetUrl }} will be imported! You can already add information about this video.
42</div>
43
44<!-- Hidden because we want to load the component -->
45<form [hidden]="!hasImportedVideo" novalidate [formGroup]="form">
46 <my-video-edit
47 [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions" [schedulePublicationPossible]="false"
48 [validationMessages]="validationMessages" [videoPrivacies]="videoPrivacies" [userVideoChannels]="userVideoChannels"
49 ></my-video-edit>
50
51 <div class="submit-container">
52 <div class="submit-button"
53 (click)="updateSecondStep()"
54 [ngClass]="{ disabled: !form.valid || isUpdatingVideo === true }"
55 >
56 <span class="icon icon-validate"></span>
57 <input type="button" i18n-value value="Update" />
58 </div>
59 </div>
60</form>
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.scss b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.scss
new file mode 100644
index 000000000..5e713ab97
--- /dev/null
+++ b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.scss
@@ -0,0 +1,37 @@
1@import 'variables';
2@import 'mixins';
3
4$width-size: 190px;
5
6.peertube-select-container {
7 @include peertube-select-container($width-size);
8}
9
10.import-video {
11 display: flex;
12 flex-direction: column;
13 align-items: center;
14
15 .icon.icon-upload {
16 @include icon(90px);
17 margin-bottom: 25px;
18 cursor: default;
19
20 background-image: url('../../../../assets/images/video/upload.svg');
21 }
22
23 input[type=text] {
24 @include peertube-input-text($width-size);
25 display: block;
26 }
27
28 input[type=button] {
29 @include peertube-button;
30 @include orange-button;
31
32 width: $width-size;
33 margin-top: 30px;
34 }
35}
36
37
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts
new file mode 100644
index 000000000..dbe69409f
--- /dev/null
+++ b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts
@@ -0,0 +1,132 @@
1import { Component, EventEmitter, OnInit, Output } from '@angular/core'
2import { Router } from '@angular/router'
3import { NotificationsService } from 'angular2-notifications'
4import { VideoPrivacy, VideoUpdate } from '../../../../../../shared/models/videos'
5import { AuthService, ServerService } from '../../../core'
6import { VideoService } from '../../../shared/video/video.service'
7import { I18n } from '@ngx-translate/i18n-polyfill'
8import { LoadingBarService } from '@ngx-loading-bar/core'
9import { VideoSend } from '@app/videos/+video-edit/video-add-components/video-send'
10import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
11import { VideoEdit } from '@app/shared/video/video-edit.model'
12import { FormValidatorService } from '@app/shared'
13import { VideoCaptionService } from '@app/shared/video-caption'
14import { VideoImportService } from '@app/shared/video-import'
15
16@Component({
17 selector: 'my-video-import-url',
18 templateUrl: './video-import-url.component.html',
19 styleUrls: [
20 '../shared/video-edit.component.scss',
21 './video-import-url.component.scss'
22 ]
23})
24export class VideoImportUrlComponent extends VideoSend implements OnInit, CanComponentDeactivate {
25 @Output() firstStepDone = new EventEmitter<string>()
26
27 targetUrl = ''
28 videoFileName: string
29
30 isImportingVideo = false
31 hasImportedVideo = false
32 isUpdatingVideo = false
33
34 video: VideoEdit
35
36 protected readonly DEFAULT_VIDEO_PRIVACY = VideoPrivacy.PRIVATE
37
38 constructor (
39 protected formValidatorService: FormValidatorService,
40 protected loadingBar: LoadingBarService,
41 protected notificationsService: NotificationsService,
42 protected authService: AuthService,
43 protected serverService: ServerService,
44 protected videoService: VideoService,
45 protected videoCaptionService: VideoCaptionService,
46 private router: Router,
47 private videoImportService: VideoImportService,
48 private i18n: I18n
49 ) {
50 super()
51 }
52
53 ngOnInit () {
54 super.ngOnInit()
55 }
56
57 canDeactivate () {
58 return { canDeactivate: true }
59 }
60
61 isTargetUrlValid () {
62 return this.targetUrl && this.targetUrl.match(/https?:\/\//)
63 }
64
65 importVideo () {
66 this.isImportingVideo = true
67
68 const videoUpdate: VideoUpdate = {
69 privacy: this.firstStepPrivacyId,
70 waitTranscoding: false,
71 commentsEnabled: true,
72 channelId: this.firstStepChannelId
73 }
74
75 this.loadingBar.start()
76
77 this.videoImportService.importVideo(this.targetUrl, videoUpdate).subscribe(
78 res => {
79 this.loadingBar.complete()
80 this.firstStepDone.emit(res.video.name)
81 this.isImportingVideo = false
82 this.hasImportedVideo = true
83
84 this.video = new VideoEdit(Object.assign(res.video, {
85 commentsEnabled: videoUpdate.commentsEnabled,
86 support: null,
87 thumbnailUrl: null,
88 previewUrl: null
89 }))
90 this.hydrateFormFromVideo()
91 },
92
93 err => {
94 this.loadingBar.complete()
95 this.isImportingVideo = false
96 this.notificationsService.error(this.i18n('Error'), err.message)
97 }
98 )
99 }
100
101 updateSecondStep () {
102 if (this.checkForm() === false) {
103 return
104 }
105
106 this.video.patch(this.form.value)
107
108 this.isUpdatingVideo = true
109
110 // Update the video
111 this.updateVideoAndCaptions(this.video)
112 .subscribe(
113 () => {
114 this.isUpdatingVideo = false
115 this.notificationsService.success(this.i18n('Success'), this.i18n('Video to import updated.'))
116
117 this.router.navigate([ '/my-account', 'video-imports' ])
118 },
119
120 err => {
121 this.isUpdatingVideo = false
122 this.notificationsService.error(this.i18n('Error'), err.message)
123 console.error(err)
124 }
125 )
126
127 }
128
129 private hydrateFormFromVideo () {
130 this.form.patchValue(this.video.toFormPatch())
131 }
132}
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-send.ts b/client/src/app/videos/+video-edit/video-add-components/video-send.ts
new file mode 100644
index 000000000..efd182269
--- /dev/null
+++ b/client/src/app/videos/+video-edit/video-add-components/video-send.ts
@@ -0,0 +1,71 @@
1import { EventEmitter, OnInit } from '@angular/core'
2import { LoadingBarService } from '@ngx-loading-bar/core'
3import { NotificationsService } from 'angular2-notifications'
4import { catchError, switchMap, tap } from 'rxjs/operators'
5import { FormReactive } from '@app/shared'
6import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
7import { VideoConstant, VideoPrivacy } from '../../../../../../shared'
8import { AuthService, ServerService } from '@app/core'
9import { VideoService } from '@app/shared/video/video.service'
10import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
11import { VideoCaptionService } from '@app/shared/video-caption'
12import { VideoEdit } from '@app/shared/video/video-edit.model'
13import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
14
15export abstract class VideoSend extends FormReactive implements OnInit, CanComponentDeactivate {
16
17 userVideoChannels: { id: number, label: string, support: string }[] = []
18 videoPrivacies: VideoConstant<string>[] = []
19 videoCaptions: VideoCaptionEdit[] = []
20
21 firstStepPrivacyId = 0
22 firstStepChannelId = 0
23
24 abstract firstStepDone: EventEmitter<string>
25 protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
26
27 protected loadingBar: LoadingBarService
28 protected notificationsService: NotificationsService
29 protected authService: AuthService
30 protected serverService: ServerService
31 protected videoService: VideoService
32 protected videoCaptionService: VideoCaptionService
33
34 abstract canDeactivate ()
35
36 ngOnInit () {
37 this.buildForm({})
38
39 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
40 .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
41
42 this.serverService.videoPrivaciesLoaded
43 .subscribe(
44 () => {
45 this.videoPrivacies = this.serverService.getVideoPrivacies()
46
47 this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
48 })
49 }
50
51 checkForm () {
52 this.forceCheck()
53
54 return this.form.valid
55 }
56
57 protected updateVideoAndCaptions (video: VideoEdit) {
58 this.loadingBar.start()
59
60 return this.videoService.updateVideo(video)
61 .pipe(
62 // Then update captions
63 switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
64 tap(() => this.loadingBar.complete()),
65 catchError(err => {
66 this.loadingBar.complete()
67 throw err
68 })
69 )
70 }
71}
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html
new file mode 100644
index 000000000..8c0723155
--- /dev/null
+++ b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html
@@ -0,0 +1,58 @@
1<div *ngIf="!isUploadingVideo" class="upload-video-container">
2 <div class="upload-video">
3 <div class="icon icon-upload"></div>
4
5 <div class="button-file">
6 <span i18n>Select the file to upload</span>
7 <input #videofileInput type="file" name="videofile" id="videofile" [accept]="videoExtensions" (change)="fileChange()" />
8 </div>
9 <span class="button-file-extension">(.mp4, .webm, .ogv)</span>
10
11 <div class="form-group form-group-channel">
12 <label i18n for="first-step-channel">Channel</label>
13 <div class="peertube-select-container">
14 <select id="first-step-channel" [(ngModel)]="firstStepChannelId">
15 <option *ngFor="let channel of userVideoChannels" [value]="channel.id">{{ channel.label }}</option>
16 </select>
17 </div>
18 </div>
19
20 <div class="form-group">
21 <label i18n for="first-step-privacy">Privacy</label>
22 <div class="peertube-select-container">
23 <select id="first-step-privacy" [(ngModel)]="firstStepPrivacyId">
24 <option *ngFor="let privacy of videoPrivacies" [value]="privacy.id">{{ privacy.label }}</option>
25 <option [value]="SPECIAL_SCHEDULED_PRIVACY">Scheduled</option>
26 </select>
27 </div>
28 </div>
29 </div>
30</div>
31
32<div *ngIf="isUploadingVideo" class="upload-progress-cancel">
33 <p-progressBar
34 [value]="videoUploadPercents"
35 [ngClass]="{ processing: videoUploadPercents === 100 && videoUploaded === false }"
36 ></p-progressBar>
37 <input *ngIf="videoUploaded === false" type="button" value="Cancel" (click)="cancelUpload()" />
38</div>
39
40<!-- Hidden because we want to load the component -->
41<form [hidden]="!isUploadingVideo" novalidate [formGroup]="form">
42 <my-video-edit
43 [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions"
44 [validationMessages]="validationMessages" [videoPrivacies]="videoPrivacies" [userVideoChannels]="userVideoChannels"
45 ></my-video-edit>
46
47 <div class="submit-container">
48 <div i18n *ngIf="videoUploaded === false" class="message-submit">Publish will be available when upload is finished</div>
49
50 <div class="submit-button"
51 (click)="updateSecondStep()"
52 [ngClass]="{ disabled: !form.valid || isUpdatingVideo === true || videoUploaded !== true }"
53 >
54 <span class="icon icon-validate"></span>
55 <input type="button" i18n-value value="Publish" />
56 </div>
57 </div>
58</form> \ No newline at end of file
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.scss b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.scss
new file mode 100644
index 000000000..dbae5230d
--- /dev/null
+++ b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.scss
@@ -0,0 +1,85 @@
1@import 'variables';
2@import 'mixins';
3
4.peertube-select-container {
5 @include peertube-select-container(190px);
6}
7
8.upload-video {
9 display: flex;
10 flex-direction: column;
11 align-items: center;
12
13 .form-group-channel {
14 margin-bottom: 20px;
15 margin-top: 35px;
16 }
17
18 .icon.icon-upload {
19 @include icon(90px);
20 margin-bottom: 25px;
21 cursor: default;
22
23 background-image: url('../../../../assets/images/video/upload.svg');
24 }
25
26 .button-file {
27 @include peertube-button-file(auto);
28
29 min-width: 190px;
30 }
31
32 .button-file-extension {
33 display: block;
34 font-size: 12px;
35 margin-top: 5px;
36 }
37}
38
39.upload-progress-cancel {
40 display: flex;
41 margin-top: 25px;
42 margin-bottom: 40px;
43
44 p-progressBar {
45 flex-grow: 1;
46
47 /deep/ .ui-progressbar {
48 font-size: 15px !important;
49 color: #fff !important;
50 height: 30px !important;
51 line-height: 30px !important;
52 border-radius: 3px !important;
53 background-color: rgba(11, 204, 41, 0.16) !important;
54
55 .ui-progressbar-value {
56 background-color: #0BCC29 !important;
57 }
58
59 .ui-progressbar-label {
60 text-align: left;
61 padding-left: 18px;
62 margin-top: 0 !important;
63 }
64 }
65
66 &.processing {
67 /deep/ .ui-progressbar-label {
68 // Same color as background to hide "100%"
69 color: rgba(11, 204, 41, 0.16) !important;
70
71 &::before {
72 content: 'Processing...';
73 color: #fff;
74 }
75 }
76 }
77 }
78
79 input {
80 @include peertube-button;
81 @include grey-button;
82
83 margin-left: 10px;
84 }
85} \ No newline at end of file
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts
new file mode 100644
index 000000000..3ec89ff62
--- /dev/null
+++ b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts
@@ -0,0 +1,219 @@
1import { HttpEventType, HttpResponse } from '@angular/common/http'
2import { Component, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
3import { Router } from '@angular/router'
4import { LoadingBarService } from '@ngx-loading-bar/core'
5import { NotificationsService } from 'angular2-notifications'
6import { BytesPipe } from 'ngx-pipes'
7import { Subscription } from 'rxjs'
8import { VideoPrivacy } from '../../../../../../shared/models/videos'
9import { AuthService, ServerService } from '../../../core'
10import { VideoEdit } from '../../../shared/video/video-edit.model'
11import { VideoService } from '../../../shared/video/video.service'
12import { I18n } from '@ngx-translate/i18n-polyfill'
13import { VideoSend } from '@app/videos/+video-edit/video-add-components/video-send'
14import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
15import { FormValidatorService, UserService } from '@app/shared'
16import { VideoCaptionService } from '@app/shared/video-caption'
17
18@Component({
19 selector: 'my-video-upload',
20 templateUrl: './video-upload.component.html',
21 styleUrls: [
22 '../shared/video-edit.component.scss',
23 './video-upload.component.scss'
24 ]
25})
26export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy, CanComponentDeactivate {
27 @Output() firstStepDone = new EventEmitter<string>()
28 @ViewChild('videofileInput') videofileInput
29
30 // So that it can be accessed in the template
31 readonly SPECIAL_SCHEDULED_PRIVACY = VideoEdit.SPECIAL_SCHEDULED_PRIVACY
32
33 userVideoQuotaUsed = 0
34
35 isUploadingVideo = false
36 isUpdatingVideo = false
37 videoUploaded = false
38 videoUploadObservable: Subscription = null
39 videoUploadPercents = 0
40 videoUploadedIds = {
41 id: 0,
42 uuid: ''
43 }
44
45 protected readonly DEFAULT_VIDEO_PRIVACY = VideoPrivacy.PUBLIC
46
47 constructor (
48 protected formValidatorService: FormValidatorService,
49 protected loadingBar: LoadingBarService,
50 protected notificationsService: NotificationsService,
51 protected authService: AuthService,
52 protected serverService: ServerService,
53 protected videoService: VideoService,
54 protected videoCaptionService: VideoCaptionService,
55 private userService: UserService,
56 private router: Router,
57 private i18n: I18n
58 ) {
59 super()
60 }
61
62 get videoExtensions () {
63 return this.serverService.getConfig().video.file.extensions.join(',')
64 }
65
66 ngOnInit () {
67 super.ngOnInit()
68
69 this.userService.getMyVideoQuotaUsed()
70 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
71 }
72
73 ngOnDestroy () {
74 if (this.videoUploadObservable) this.videoUploadObservable.unsubscribe()
75 }
76
77 canDeactivate () {
78 let text = ''
79
80 if (this.videoUploaded === true) {
81 // FIXME: cannot concatenate strings inside i18n service :/
82 text = this.i18n('Your video was uploaded to your account and is private.') +
83 this.i18n('But associated data (tags, description...) will be lost, are you sure you want to leave this page?')
84 } else {
85 text = this.i18n('Your video is not uploaded yet, are you sure you want to leave this page?')
86 }
87
88 return {
89 canDeactivate: !this.isUploadingVideo,
90 text
91 }
92 }
93
94 fileChange () {
95 this.uploadFirstStep()
96 }
97
98 cancelUpload () {
99 if (this.videoUploadObservable !== null) {
100 this.videoUploadObservable.unsubscribe()
101 this.isUploadingVideo = false
102 this.videoUploadPercents = 0
103 this.videoUploadObservable = null
104 this.notificationsService.info(this.i18n('Info'), this.i18n('Upload cancelled'))
105 }
106 }
107
108 uploadFirstStep () {
109 const videofile = this.videofileInput.nativeElement.files[0] as File
110 if (!videofile) return
111
112 // Cannot upload videos > 8GB for now
113 if (videofile.size > 8 * 1024 * 1024 * 1024) {
114 this.notificationsService.error(this.i18n('Error'), this.i18n('We are sorry but PeerTube cannot handle videos > 8GB'))
115 return
116 }
117
118 const videoQuota = this.authService.getUser().videoQuota
119 if (videoQuota !== -1 && (this.userVideoQuotaUsed + videofile.size) > videoQuota) {
120 const bytePipes = new BytesPipe()
121
122 const msg = this.i18n(
123 'Your video quota is exceeded with this video (video size: {{ videoSize }}, used: {{ videoQuotaUsed }}, quota: {{ videoQuota }})',
124 {
125 videoSize: bytePipes.transform(videofile.size, 0),
126 videoQuotaUsed: bytePipes.transform(this.userVideoQuotaUsed, 0),
127 videoQuota: bytePipes.transform(videoQuota, 0)
128 }
129 )
130 this.notificationsService.error(this.i18n('Error'), msg)
131 return
132 }
133
134 const nameWithoutExtension = videofile.name.replace(/\.[^/.]+$/, '')
135 let name: string
136
137 // If the name of the file is very small, keep the extension
138 if (nameWithoutExtension.length < 3) name = videofile.name
139 else name = nameWithoutExtension
140
141 const privacy = this.firstStepPrivacyId.toString()
142 const nsfw = false
143 const waitTranscoding = true
144 const commentsEnabled = true
145 const channelId = this.firstStepChannelId.toString()
146
147 const formData = new FormData()
148 formData.append('name', name)
149 // Put the video "private" -> we are waiting the user validation of the second step
150 formData.append('privacy', VideoPrivacy.PRIVATE.toString())
151 formData.append('nsfw', '' + nsfw)
152 formData.append('commentsEnabled', '' + commentsEnabled)
153 formData.append('waitTranscoding', '' + waitTranscoding)
154 formData.append('channelId', '' + channelId)
155 formData.append('videofile', videofile)
156
157 this.isUploadingVideo = true
158 this.firstStepDone.emit(name)
159
160 this.form.patchValue({
161 name,
162 privacy,
163 nsfw,
164 channelId
165 })
166
167 this.videoUploadObservable = this.videoService.uploadVideo(formData).subscribe(
168 event => {
169 if (event.type === HttpEventType.UploadProgress) {
170 this.videoUploadPercents = Math.round(100 * event.loaded / event.total)
171 } else if (event instanceof HttpResponse) {
172 this.videoUploaded = true
173
174 this.videoUploadedIds = event.body.video
175
176 this.videoUploadObservable = null
177 }
178 },
179
180 err => {
181 // Reset progress
182 this.isUploadingVideo = false
183 this.videoUploadPercents = 0
184 this.videoUploadObservable = null
185 this.notificationsService.error(this.i18n('Error'), err.message)
186 }
187 )
188 }
189
190 updateSecondStep () {
191 if (this.checkForm() === false) {
192 return
193 }
194
195 const video = new VideoEdit()
196 video.patch(this.form.value)
197 video.id = this.videoUploadedIds.id
198 video.uuid = this.videoUploadedIds.uuid
199
200 this.isUpdatingVideo = true
201
202 this.updateVideoAndCaptions(video)
203 .subscribe(
204 () => {
205 this.isUpdatingVideo = false
206 this.isUploadingVideo = false
207
208 this.notificationsService.success(this.i18n('Success'), this.i18n('Video published.'))
209 this.router.navigate([ '/videos/watch', video.uuid ])
210 },
211
212 err => {
213 this.isUpdatingVideo = false
214 this.notificationsService.error(this.i18n('Error'), err.message)
215 console.error(err)
216 }
217 )
218 }
219}