@@ -2,6 +2,7 @@ import { Component, ElementRef, HostListener, OnDestroy, OnInit, ViewChild } fro
22
33import { Subscription } from 'rxjs' ;
44
5+ import { AuthService } from '@services/auth.service' ;
56import { FileService } from '@services/file.service' ;
67import { ModalService } from '@services/modal.service' ;
78
@@ -25,6 +26,8 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
2526 private openModalSubscription : Subscription ;
2627 private modalOpened = false ;
2728 private folderId : string ;
29+ usedSpace : number ;
30+ totalSpace : number ;
2831
2932 uploading = false ;
3033
@@ -34,6 +37,7 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
3437 constructor (
3538 private modalService : ModalService ,
3639 private fileService : FileService ,
40+ private authService : AuthService
3741 ) { }
3842
3943 ngOnDestroy ( ) : void {
@@ -44,6 +48,8 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
4448 this . openModalSubscription = this . modalService . openNewFileModal
4549 . subscribe ( ( { folderID } ) => {
4650 this . folderId = folderID ;
51+ this . usedSpace = this . authService . userActive . usedSpace ;
52+ this . totalSpace = this . authService . userActive . totalSpace ;
4753 this . openModal ( ) ;
4854 } ) ;
4955 }
@@ -71,6 +77,7 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
7177 return file ;
7278 } ) ;
7379 this . files = [ ...this . files , ...files ] ;
80+ this . validateUsedSpace ( ) ;
7481 }
7582
7683 getIcon ( file : File ) : string {
@@ -86,7 +93,19 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
8693 && ALLOWED_FILE_TYPES . includes ( file . type ) ) ;
8794 }
8895
96+ validateUsedSpace ( ) : boolean {
97+ const totalSize = this . files . reduce ( ( acc , file ) => acc + file . size , 0 ) ;
98+ return this . usedSpace + totalSize <= this . totalSpace ;
99+ }
100+
101+ get getUsedSpace ( ) : number {
102+ return this . usedSpace ;
103+ }
104+
89105 uploadFiles ( ) : void {
106+ if ( ! this . validateUsedSpace ( ) ) {
107+ return ;
108+ }
90109 if ( this . validateFiles ( ) && this . folderId ) {
91110 this . uploading = true ;
92111 this . fileService . createFiles ( this . files , this . folderId ) . subscribe ( {
0 commit comments