diff options
Diffstat (limited to 'client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts')
-rw-r--r-- | client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts | 108 |
1 files changed, 76 insertions, 32 deletions
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 index d6d4bad21..69fa13a2f 100644 --- 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 | |||
@@ -35,8 +35,10 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
35 | userVideoQuotaUsed = 0 | 35 | userVideoQuotaUsed = 0 |
36 | userVideoQuotaUsedDaily = 0 | 36 | userVideoQuotaUsedDaily = 0 |
37 | 37 | ||
38 | isUploadingAudioFile = false | ||
38 | isUploadingVideo = false | 39 | isUploadingVideo = false |
39 | isUpdatingVideo = false | 40 | isUpdatingVideo = false |
41 | |||
40 | videoUploaded = false | 42 | videoUploaded = false |
41 | videoUploadObservable: Subscription = null | 43 | videoUploadObservable: Subscription = null |
42 | videoUploadPercents = 0 | 44 | videoUploadPercents = 0 |
@@ -44,7 +46,9 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
44 | id: 0, | 46 | id: 0, |
45 | uuid: '' | 47 | uuid: '' |
46 | } | 48 | } |
49 | |||
47 | waitTranscodingEnabled = true | 50 | waitTranscodingEnabled = true |
51 | previewfileUpload: File | ||
48 | 52 | ||
49 | error: string | 53 | error: string |
50 | 54 | ||
@@ -100,6 +104,17 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
100 | } | 104 | } |
101 | } | 105 | } |
102 | 106 | ||
107 | getVideoFile () { | ||
108 | return this.videofileInput.nativeElement.files[0] | ||
109 | } | ||
110 | |||
111 | getAudioUploadLabel () { | ||
112 | const videofile = this.getVideoFile() | ||
113 | if (!videofile) return this.i18n('Upload') | ||
114 | |||
115 | return this.i18n('Upload {{videofileName}}', { videofileName: videofile.name }) | ||
116 | } | ||
117 | |||
103 | fileChange () { | 118 | fileChange () { |
104 | this.uploadFirstStep() | 119 | this.uploadFirstStep() |
105 | } | 120 | } |
@@ -114,38 +129,15 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
114 | } | 129 | } |
115 | } | 130 | } |
116 | 131 | ||
117 | uploadFirstStep () { | 132 | uploadFirstStep (clickedOnButton = false) { |
118 | const videofile = this.videofileInput.nativeElement.files[0] | 133 | const videofile = this.getVideoFile() |
119 | if (!videofile) return | 134 | if (!videofile) return |
120 | 135 | ||
121 | // Check global user quota | 136 | if (!this.checkGlobalUserQuota(videofile)) return |
122 | const bytePipes = new BytesPipe() | 137 | if (!this.checkDailyUserQuota(videofile)) return |
123 | const videoQuota = this.authService.getUser().videoQuota | ||
124 | if (videoQuota !== -1 && (this.userVideoQuotaUsed + videofile.size) > videoQuota) { | ||
125 | const msg = this.i18n( | ||
126 | 'Your video quota is exceeded with this video (video size: {{videoSize}}, used: {{videoQuotaUsed}}, quota: {{videoQuota}})', | ||
127 | { | ||
128 | videoSize: bytePipes.transform(videofile.size, 0), | ||
129 | videoQuotaUsed: bytePipes.transform(this.userVideoQuotaUsed, 0), | ||
130 | videoQuota: bytePipes.transform(videoQuota, 0) | ||
131 | } | ||
132 | ) | ||
133 | this.notifier.error(msg) | ||
134 | return | ||
135 | } | ||
136 | 138 | ||
137 | // Check daily user quota | 139 | if (clickedOnButton === false && this.isAudioFile(videofile.name)) { |
138 | const videoQuotaDaily = this.authService.getUser().videoQuotaDaily | 140 | this.isUploadingAudioFile = true |
139 | if (videoQuotaDaily !== -1 && (this.userVideoQuotaUsedDaily + videofile.size) > videoQuotaDaily) { | ||
140 | const msg = this.i18n( | ||
141 | 'Your daily video quota is exceeded with this video (video size: {{videoSize}}, used: {{quotaUsedDaily}}, quota: {{quotaDaily}})', | ||
142 | { | ||
143 | videoSize: bytePipes.transform(videofile.size, 0), | ||
144 | quotaUsedDaily: bytePipes.transform(this.userVideoQuotaUsedDaily, 0), | ||
145 | quotaDaily: bytePipes.transform(videoQuotaDaily, 0) | ||
146 | } | ||
147 | ) | ||
148 | this.notifier.error(msg) | ||
149 | return | 141 | return |
150 | } | 142 | } |
151 | 143 | ||
@@ -180,6 +172,11 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
180 | formData.append('channelId', '' + channelId) | 172 | formData.append('channelId', '' + channelId) |
181 | formData.append('videofile', videofile) | 173 | formData.append('videofile', videofile) |
182 | 174 | ||
175 | if (this.previewfileUpload) { | ||
176 | formData.append('previewfile', this.previewfileUpload) | ||
177 | formData.append('thumbnailfile', this.previewfileUpload) | ||
178 | } | ||
179 | |||
183 | this.isUploadingVideo = true | 180 | this.isUploadingVideo = true |
184 | this.firstStepDone.emit(name) | 181 | this.firstStepDone.emit(name) |
185 | 182 | ||
@@ -187,11 +184,10 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
187 | name, | 184 | name, |
188 | privacy, | 185 | privacy, |
189 | nsfw, | 186 | nsfw, |
190 | channelId | 187 | channelId, |
188 | previewfile: this.previewfileUpload | ||
191 | }) | 189 | }) |
192 | 190 | ||
193 | this.explainedVideoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies) | ||
194 | |||
195 | this.videoUploadObservable = this.videoService.uploadVideo(formData).subscribe( | 191 | this.videoUploadObservable = this.videoService.uploadVideo(formData).subscribe( |
196 | event => { | 192 | event => { |
197 | if (event.type === HttpEventType.UploadProgress) { | 193 | if (event.type === HttpEventType.UploadProgress) { |
@@ -251,4 +247,52 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
251 | } | 247 | } |
252 | ) | 248 | ) |
253 | } | 249 | } |
250 | |||
251 | private checkGlobalUserQuota (videofile: File) { | ||
252 | const bytePipes = new BytesPipe() | ||
253 | |||
254 | // Check global user quota | ||
255 | const videoQuota = this.authService.getUser().videoQuota | ||
256 | if (videoQuota !== -1 && (this.userVideoQuotaUsed + videofile.size) > videoQuota) { | ||
257 | const msg = this.i18n( | ||
258 | 'Your video quota is exceeded with this video (video size: {{videoSize}}, used: {{videoQuotaUsed}}, quota: {{videoQuota}})', | ||
259 | { | ||
260 | videoSize: bytePipes.transform(videofile.size, 0), | ||
261 | videoQuotaUsed: bytePipes.transform(this.userVideoQuotaUsed, 0), | ||
262 | videoQuota: bytePipes.transform(videoQuota, 0) | ||
263 | } | ||
264 | ) | ||
265 | this.notifier.error(msg) | ||
266 | |||
267 | return false | ||
268 | } | ||
269 | |||
270 | return true | ||
271 | } | ||
272 | |||
273 | private checkDailyUserQuota (videofile: File) { | ||
274 | const bytePipes = new BytesPipe() | ||
275 | |||
276 | // Check daily user quota | ||
277 | const videoQuotaDaily = this.authService.getUser().videoQuotaDaily | ||
278 | if (videoQuotaDaily !== -1 && (this.userVideoQuotaUsedDaily + videofile.size) > videoQuotaDaily) { | ||
279 | const msg = this.i18n( | ||
280 | 'Your daily video quota is exceeded with this video (video size: {{videoSize}}, used: {{quotaUsedDaily}}, quota: {{quotaDaily}})', | ||
281 | { | ||
282 | videoSize: bytePipes.transform(videofile.size, 0), | ||
283 | quotaUsedDaily: bytePipes.transform(this.userVideoQuotaUsedDaily, 0), | ||
284 | quotaDaily: bytePipes.transform(videoQuotaDaily, 0) | ||
285 | } | ||
286 | ) | ||
287 | this.notifier.error(msg) | ||
288 | |||
289 | return false | ||
290 | } | ||
291 | |||
292 | return true | ||
293 | } | ||
294 | |||
295 | private isAudioFile (filename: string) { | ||
296 | return filename.endsWith('.mp3') || filename.endsWith('.flac') || filename.endsWith('.ogg') | ||
297 | } | ||
254 | } | 298 | } |