@@ -2,6 +2,7 @@ import { Component, ElementRef, HostListener, OnDestroy, OnInit, ViewChild } fro
2
2
3
3
import { Subscription } from 'rxjs' ;
4
4
5
+ import { AuthService } from '@services/auth.service' ;
5
6
import { FileService } from '@services/file.service' ;
6
7
import { ModalService } from '@services/modal.service' ;
7
8
@@ -25,6 +26,8 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
25
26
private openModalSubscription : Subscription ;
26
27
private modalOpened = false ;
27
28
private folderId : string ;
29
+ usedSpace : number ;
30
+ totalSpace : number ;
28
31
29
32
uploading = false ;
30
33
@@ -34,6 +37,7 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
34
37
constructor (
35
38
private modalService : ModalService ,
36
39
private fileService : FileService ,
40
+ private authService : AuthService
37
41
) { }
38
42
39
43
ngOnDestroy ( ) : void {
@@ -44,6 +48,8 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
44
48
this . openModalSubscription = this . modalService . openNewFileModal
45
49
. subscribe ( ( { folderID } ) => {
46
50
this . folderId = folderID ;
51
+ this . usedSpace = this . authService . userActive . usedSpace ;
52
+ this . totalSpace = this . authService . userActive . totalSpace ;
47
53
this . openModal ( ) ;
48
54
} ) ;
49
55
}
@@ -71,6 +77,7 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
71
77
return file ;
72
78
} ) ;
73
79
this . files = [ ...this . files , ...files ] ;
80
+ this . validateUsedSpace ( ) ;
74
81
}
75
82
76
83
getIcon ( file : File ) : string {
@@ -86,7 +93,19 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
86
93
&& ALLOWED_FILE_TYPES . includes ( file . type ) ) ;
87
94
}
88
95
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
+
89
105
uploadFiles ( ) : void {
106
+ if ( ! this . validateUsedSpace ( ) ) {
107
+ return ;
108
+ }
90
109
if ( this . validateFiles ( ) && this . folderId ) {
91
110
this . uploading = true ;
92
111
this . fileService . createFiles ( this . files , this . folderId ) . subscribe ( {
0 commit comments