@@ -7,12 +7,10 @@ import os from "os";
77import { FileService } from "../services/FileService" ;
88
99const upload = multer ( {
10- limits : { fileSize : 1024 * 1024 * 1024 } , // 1GB limit
1110 storage : multer . memoryStorage ( ) ,
1211} ) ;
1312
1413const uploadMultiple = multer ( {
15- limits : { fileSize : 1024 * 1024 * 1024 } , // 1GB limit
1614 storage : multer . memoryStorage ( ) ,
1715} ) ;
1816
@@ -43,19 +41,19 @@ export class FileController {
4341 . json ( { error : "Authentication required" } ) ;
4442 }
4543
46- // Check file size limit (1GB)
47- const MAX_FILE_SIZE = 1024 * 1024 * 1024 ; // 1GB in bytes
48- if ( req . file . size > MAX_FILE_SIZE ) {
44+ // Check user's storage quota
45+ const { used, limit } =
46+ await this . fileService . getUserStorageUsage ( req . user . id ) ;
47+
48+ // Check individual file size against user's limit
49+ if ( req . file . size > limit ) {
4950 return res . status ( 413 ) . json ( {
50- error : " File size exceeds 1GB limit" ,
51- maxSize : MAX_FILE_SIZE ,
51+ error : ` File size exceeds ${ Math . round ( limit / ( 1024 * 1024 * 1024 ) ) } GB limit` ,
52+ maxSize : limit ,
5253 fileSize : req . file . size ,
5354 } ) ;
5455 }
5556
56- // Check user's storage quota (1GB total)
57- const { used, limit } =
58- await this . fileService . getUserStorageUsage ( req . user . id ) ;
5957 if ( used + req . file . size > limit ) {
6058 return res . status ( 413 ) . json ( {
6159 error : "Storage quota exceeded" ,
@@ -124,7 +122,6 @@ export class FileController {
124122 . json ( { error : "Authentication required" } ) ;
125123 }
126124
127- const MAX_FILE_SIZE = 1024 * 1024 * 1024 ; // 1GB in bytes
128125 const { used, limit } =
129126 await this . fileService . getUserStorageUsage ( req . user . id ) ;
130127
@@ -169,10 +166,10 @@ export class FileController {
169166 for ( const file of files ) {
170167 try {
171168 // Check file size limit
172- if ( file . size > MAX_FILE_SIZE ) {
169+ if ( file . size > limit ) {
173170 errors . push ( {
174171 fileName : file . originalname ,
175- error : " File size exceeds 1GB limit" ,
172+ error : ` File size exceeds ${ Math . round ( limit / ( 1024 * 1024 * 1024 ) ) } GB limit` ,
176173 fileSize : file . size ,
177174 } ) ;
178175 continue ;
0 commit comments