Skip to content

Commit d6675ba

Browse files
committed
Merge branch '4.0.0-dev' of https://github.com/themeum/tutor into shewa-v4
2 parents 5e80eee + d0eb3bb commit d6675ba

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

assets/core/ts/components/file-uploader.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,35 @@ export const fileUploader = (props: FileUploaderProps = defaultProps) => ({
234234

235235
if (this.multiple) {
236236
const mergedFiles = this.mergeFileLists(this.selectedFiles, validFiles);
237+
const totalFileSize = mergedFiles.reduce((total, current) => {
238+
if (typeof current === 'string') {
239+
return 0;
240+
}
241+
return total + Math.round(Number(current?.size) || 0);
242+
}, 0);
237243

238244
if (this.maxFiles && mergedFiles.length > this.maxFiles) {
239245
this.showError(
240246
sprintf(
241-
// translators: %d is the maximum number of files allowed
247+
// translators: %d is the maximum number of files allowed.
242248
__('Cannot select more than %d files', 'tutor'),
243249
this.maxFiles,
244250
),
245251
);
246252
return;
247253
}
248254

255+
if (totalFileSize > this.maxSize) {
256+
this.showError(
257+
sprintf(
258+
// translators: %1$s is the maximum allowed size.
259+
__('Maximum allowed size is %1$s.', 'tutor'),
260+
formatBytes(this.maxSize),
261+
),
262+
);
263+
return;
264+
}
265+
249266
this.selectedFiles = mergedFiles;
250267
} else {
251268
this.selectedFiles = [validFiles[0]];

0 commit comments

Comments
 (0)