@@ -136,12 +136,13 @@ export const checkUploadPermissions = async <
136
136
allowed_mime_types,
137
137
blocked_file_extensions,
138
138
blocked_mime_types,
139
+ size_limit,
139
140
} =
140
141
( ( uploadType === 'image'
141
142
? appSettings ?. app ?. image_upload_config
142
143
: appSettings ?. app ?. file_upload_config ) as FileUploadConfig ) || { } ;
143
144
144
- const sendErrorNotification = ( ) =>
145
+ const sendNotAllowedErrorNotification = ( ) =>
145
146
addNotification (
146
147
t ( `Upload type: "{{ type }}" is not allowed` , { type : file . type || 'unknown type' } ) ,
147
148
'error' ,
@@ -153,7 +154,7 @@ export const checkUploadPermissions = async <
153
154
) ;
154
155
155
156
if ( ! allowed ) {
156
- sendErrorNotification ( ) ;
157
+ sendNotAllowedErrorNotification ( ) ;
157
158
return false ;
158
159
}
159
160
}
@@ -164,7 +165,7 @@ export const checkUploadPermissions = async <
164
165
) ;
165
166
166
167
if ( blocked ) {
167
- sendErrorNotification ( ) ;
168
+ sendNotAllowedErrorNotification ( ) ;
168
169
return false ;
169
170
}
170
171
}
@@ -175,7 +176,7 @@ export const checkUploadPermissions = async <
175
176
) ;
176
177
177
178
if ( ! allowed ) {
178
- sendErrorNotification ( ) ;
179
+ sendNotAllowedErrorNotification ( ) ;
179
180
return false ;
180
181
}
181
182
}
@@ -186,10 +187,28 @@ export const checkUploadPermissions = async <
186
187
) ;
187
188
188
189
if ( blocked ) {
189
- sendErrorNotification ( ) ;
190
+ sendNotAllowedErrorNotification ( ) ;
190
191
return false ;
191
192
}
192
193
}
193
194
195
+ if ( file . size && size_limit && file . size > size_limit ) {
196
+ addNotification (
197
+ t ( 'File is too large: {{ size }}, maximum upload size is {{ limit }}' , {
198
+ limit : prettifyFileSize ( size_limit ) ,
199
+ size : prettifyFileSize ( file . size ) ,
200
+ } ) ,
201
+ 'error' ,
202
+ ) ;
203
+ return false ;
204
+ }
205
+
194
206
return true ;
195
207
} ;
208
+
209
+ function prettifyFileSize ( bytes : number ) {
210
+ const units = [ 'B' , 'kB' , 'MB' , 'GB' ] ;
211
+ const exponent = Math . min ( Math . floor ( Math . log ( bytes ) / Math . log ( 1024 ) ) , units . length - 1 ) ;
212
+ const mantissa = bytes / 1024 ** exponent ;
213
+ return `${ mantissa . toPrecision ( 3 ) } ${ units [ exponent ] } ` ;
214
+ }
0 commit comments