aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-edit/video-add.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos/+video-edit/video-add.component.ts')
-rw-r--r--client/src/app/videos/+video-edit/video-add.component.ts25
1 files changed, 22 insertions, 3 deletions
diff --git a/client/src/app/videos/+video-edit/video-add.component.ts b/client/src/app/videos/+video-edit/video-add.component.ts
index 066f945fc..a86d9d3c2 100644
--- a/client/src/app/videos/+video-edit/video-add.component.ts
+++ b/client/src/app/videos/+video-edit/video-add.component.ts
@@ -2,7 +2,9 @@ import { HttpEventType, HttpResponse } from '@angular/common/http'
2import { Component, OnInit, ViewChild } from '@angular/core' 2import { Component, OnInit, ViewChild } from '@angular/core'
3import { FormBuilder, FormGroup } from '@angular/forms' 3import { FormBuilder, FormGroup } from '@angular/forms'
4import { Router } from '@angular/router' 4import { Router } from '@angular/router'
5import { UserService } from '@app/shared'
5import { NotificationsService } from 'angular2-notifications' 6import { NotificationsService } from 'angular2-notifications'
7import { BytesPipe } from 'ngx-pipes'
6import { VideoPrivacy } from '../../../../../shared/models/videos' 8import { VideoPrivacy } from '../../../../../shared/models/videos'
7import { AuthService, ServerService } from '../../core' 9import { AuthService, ServerService } from '../../core'
8import { FormReactive } from '../../shared' 10import { FormReactive } from '../../shared'
@@ -31,12 +33,12 @@ export class VideoAddComponent extends FormReactive implements OnInit {
31 uuid: '' 33 uuid: ''
32 } 34 }
33 35
34 error: string = null
35 form: FormGroup 36 form: FormGroup
36 formErrors: { [ id: string ]: string } = {} 37 formErrors: { [ id: string ]: string } = {}
37 validationMessages: ValidatorMessage = {} 38 validationMessages: ValidatorMessage = {}
38 39
39 userVideoChannels = [] 40 userVideoChannels = []
41 userVideoQuotaUsed = 0
40 videoPrivacies = [] 42 videoPrivacies = []
41 firstStepPrivacyId = 0 43 firstStepPrivacyId = 0
42 firstStepChannelId = 0 44 firstStepChannelId = 0
@@ -46,6 +48,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
46 private router: Router, 48 private router: Router,
47 private notificationsService: NotificationsService, 49 private notificationsService: NotificationsService,
48 private authService: AuthService, 50 private authService: AuthService,
51 private userService: UserService,
49 private serverService: ServerService, 52 private serverService: ServerService,
50 private videoService: VideoService 53 private videoService: VideoService
51 ) { 54 ) {
@@ -67,6 +70,9 @@ export class VideoAddComponent extends FormReactive implements OnInit {
67 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) 70 populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
68 .then(() => this.firstStepChannelId = this.userVideoChannels[0].id) 71 .then(() => this.firstStepChannelId = this.userVideoChannels[0].id)
69 72
73 this.userService.getMyVideoQuotaUsed()
74 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
75
70 this.serverService.videoPrivaciesLoaded 76 this.serverService.videoPrivaciesLoaded
71 .subscribe( 77 .subscribe(
72 () => { 78 () => {
@@ -89,6 +95,18 @@ export class VideoAddComponent extends FormReactive implements OnInit {
89 95
90 uploadFirstStep () { 96 uploadFirstStep () {
91 const videofile = this.videofileInput.nativeElement.files[0] 97 const videofile = this.videofileInput.nativeElement.files[0]
98 const videoQuota = this.authService.getUser().videoQuota
99 if ((this.userVideoQuotaUsed + videofile.size) > videoQuota) {
100 const bytePipes = new BytesPipe()
101
102 const msg = 'Your video quota is exceeded with this video ' +
103 `(video size: ${bytePipes.transform(videofile.size, 0)}, ` +
104 `used: ${bytePipes.transform(this.userVideoQuotaUsed, 0)}, ` +
105 `quota: ${bytePipes.transform(videoQuota, 0)})`
106 this.notificationsService.error('Error', msg)
107 return
108 }
109
92 const name = videofile.name.replace(/\.[^/.]+$/, '') 110 const name = videofile.name.replace(/\.[^/.]+$/, '')
93 const privacy = this.firstStepPrivacyId.toString() 111 const privacy = this.firstStepPrivacyId.toString()
94 const nsfw = false 112 const nsfw = false
@@ -127,8 +145,9 @@ export class VideoAddComponent extends FormReactive implements OnInit {
127 145
128 err => { 146 err => {
129 // Reset progress 147 // Reset progress
148 this.isUploadingVideo = false
130 this.videoUploadPercents = 0 149 this.videoUploadPercents = 0
131 this.error = err.message 150 this.notificationsService.error('Error', err.message)
132 } 151 }
133 ) 152 )
134 } 153 }
@@ -152,7 +171,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
152 }, 171 },
153 172
154 err => { 173 err => {
155 this.error = 'Cannot update the video.' 174 this.notificationsService.error('Error', err.message)
156 console.error(err) 175 console.error(err)
157 } 176 }
158 ) 177 )