]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-edit/video-add.component.ts
Update translations
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add.component.ts
index a107ad1237d6340fadcc15712df050e2ccb8c9df..460c37a38e007443c8b1905a1e7fe1726d1af632 100644 (file)
@@ -1,6 +1,13 @@
 import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
-import { AuthService, AuthUser, CanComponentDeactivate, HooksService, ServerService } from '@app/core'
+import {
+  AuthService,
+  AuthUser,
+  CanComponentDeactivate,
+  HooksService,
+  ServerService,
+  UserService
+} from '@app/core'
 import { HTMLServerConfig } from '@shared/models'
 import { VideoEditType } from './shared/video-edit.type'
 import { VideoGoLiveComponent } from './video-add-components/video-go-live.component'
@@ -33,10 +40,14 @@ export class VideoAddComponent implements OnInit, CanComponentDeactivate {
     quotaLeft: string
   }
 
-  private serverConfig: HTMLServerConfig
+  hasNoQuotaLeft = false
+  hasNoQuotaLeftDaily = false
+
+  serverConfig: HTMLServerConfig
 
   constructor (
     private auth: AuthService,
+    private userService: UserService,
     private hooks: HooksService,
     private serverService: ServerService,
     private route: ActivatedRoute,
@@ -56,13 +67,34 @@ export class VideoAddComponent implements OnInit, CanComponentDeactivate {
 
     this.serverConfig = this.serverService.getHTMLConfig()
 
-    this.user = this.auth.getUser()
-
     if (this.route.snapshot.fragment) {
       this.onNavChange(this.route.snapshot.fragment)
     }
 
     this.buildUploadMessages()
+
+    this.userService.getMyVideoQuotaUsed()
+      .subscribe(data => {
+        // videoQuota left lower than 10%
+        if (data.videoQuotaUsed > this.user.videoQuota * 0.9) {
+          this.hasNoQuotaLeft = true
+        }
+
+        // unlimited videoQuota
+        if (this.user.videoQuota === -1) {
+          this.hasNoQuotaLeft = false
+        }
+
+        // videoQuotaDaily left lower than 10%
+        if (data.videoQuotaUsedDaily > this.user.videoQuotaDaily * 0.9) {
+          this.hasNoQuotaLeftDaily = true
+        }
+
+        // unlimited videoQuotaDaily
+        if (this.user.videoQuotaDaily === -1) {
+          this.hasNoQuotaLeftDaily = false
+        }
+      })
   }
 
   private async buildUploadMessages () {
@@ -111,7 +143,8 @@ export class VideoAddComponent implements OnInit, CanComponentDeactivate {
     return text
   }
 
-  canDeactivate (): { canDeactivate: boolean, text?: string} {
+  canDeactivate (): { canDeactivate: boolean, text?: string } {
+    if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
     if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
     if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
     if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate()