From ce5496d6a31b9617aba67970f5dc135e73335234 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 8 Jan 2018 12:53:09 +0100 Subject: Support video quota on client --- .../videos/+video-edit/video-add.component.html | 2 -- .../app/videos/+video-edit/video-add.component.ts | 25 +++++++++++++++++++--- .../videos/+video-edit/video-update.component.ts | 5 ++--- 3 files changed, 24 insertions(+), 8 deletions(-) (limited to 'client/src/app/videos') diff --git a/client/src/app/videos/+video-edit/video-add.component.html b/client/src/app/videos/+video-edit/video-add.component.html index 193cc55ee..2040ff9d4 100644 --- a/client/src/app/videos/+video-edit/video-add.component.html +++ b/client/src/app/videos/+video-edit/video-add.component.html @@ -3,8 +3,6 @@ Upload your video -
{{ error }}
-
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' import { Component, OnInit, ViewChild } from '@angular/core' import { FormBuilder, FormGroup } from '@angular/forms' import { Router } from '@angular/router' +import { UserService } from '@app/shared' import { NotificationsService } from 'angular2-notifications' +import { BytesPipe } from 'ngx-pipes' import { VideoPrivacy } from '../../../../../shared/models/videos' import { AuthService, ServerService } from '../../core' import { FormReactive } from '../../shared' @@ -31,12 +33,12 @@ export class VideoAddComponent extends FormReactive implements OnInit { uuid: '' } - error: string = null form: FormGroup formErrors: { [ id: string ]: string } = {} validationMessages: ValidatorMessage = {} userVideoChannels = [] + userVideoQuotaUsed = 0 videoPrivacies = [] firstStepPrivacyId = 0 firstStepChannelId = 0 @@ -46,6 +48,7 @@ export class VideoAddComponent extends FormReactive implements OnInit { private router: Router, private notificationsService: NotificationsService, private authService: AuthService, + private userService: UserService, private serverService: ServerService, private videoService: VideoService ) { @@ -67,6 +70,9 @@ export class VideoAddComponent extends FormReactive implements OnInit { populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) .then(() => this.firstStepChannelId = this.userVideoChannels[0].id) + this.userService.getMyVideoQuotaUsed() + .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed) + this.serverService.videoPrivaciesLoaded .subscribe( () => { @@ -89,6 +95,18 @@ export class VideoAddComponent extends FormReactive implements OnInit { uploadFirstStep () { const videofile = this.videofileInput.nativeElement.files[0] + const videoQuota = this.authService.getUser().videoQuota + if ((this.userVideoQuotaUsed + videofile.size) > videoQuota) { + const bytePipes = new BytesPipe() + + const msg = 'Your video quota is exceeded with this video ' + + `(video size: ${bytePipes.transform(videofile.size, 0)}, ` + + `used: ${bytePipes.transform(this.userVideoQuotaUsed, 0)}, ` + + `quota: ${bytePipes.transform(videoQuota, 0)})` + this.notificationsService.error('Error', msg) + return + } + const name = videofile.name.replace(/\.[^/.]+$/, '') const privacy = this.firstStepPrivacyId.toString() const nsfw = false @@ -127,8 +145,9 @@ export class VideoAddComponent extends FormReactive implements OnInit { err => { // Reset progress + this.isUploadingVideo = false this.videoUploadPercents = 0 - this.error = err.message + this.notificationsService.error('Error', err.message) } ) } @@ -152,7 +171,7 @@ export class VideoAddComponent extends FormReactive implements OnInit { }, err => { - this.error = 'Cannot update the video.' + this.notificationsService.error('Error', err.message) console.error(err) } ) diff --git a/client/src/app/videos/+video-edit/video-update.component.ts b/client/src/app/videos/+video-edit/video-update.component.ts index 941ef2478..7f41b56d8 100644 --- a/client/src/app/videos/+video-edit/video-update.component.ts +++ b/client/src/app/videos/+video-edit/video-update.component.ts @@ -21,7 +21,6 @@ import { VideoService } from '../../shared/video/video.service' export class VideoUpdateComponent extends FormReactive implements OnInit { video: VideoEdit - error: string = null form: FormGroup formErrors: { [ id: string ]: string } = {} validationMessages: ValidatorMessage = {} @@ -82,7 +81,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { err => { console.error(err) - this.error = 'Cannot fetch video.' + this.notificationsService.error('Error', err.message) } ) } @@ -108,7 +107,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { }, err => { - this.error = 'Cannot update the video.' + this.notificationsService.error('Error', err.message) console.error(err) } ) -- cgit v1.2.3