mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-02 21:51:51 +08:00
Merge pull request #337 from ZmagoD/zd_SCI_740
limits max size of all uploaded files at the one time
This commit is contained in:
commit
d54007f69c
2 changed files with 23 additions and 0 deletions
|
@ -108,6 +108,7 @@ function filesValidator(ev, fileInputs, fileTypeEnum, canBeEmpty) {
|
|||
if (fileInputs.length) {
|
||||
var filesPresentValid = canBeEmpty || filesPresentValidator(ev, fileInputs);
|
||||
var filesSizeValid = filesSizeValidator(ev, fileInputs, fileTypeEnum);
|
||||
|
||||
// File spoof check is done on server-side only
|
||||
filesValid = filesPresentValid && filesSizeValid;
|
||||
}
|
||||
|
@ -142,11 +143,32 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
|
|||
}
|
||||
};
|
||||
|
||||
function checkFilesTotalSize(fileInputs) {
|
||||
if (!fileInputs || fileInputs < 2) {
|
||||
return ;
|
||||
}
|
||||
|
||||
var size = 0;
|
||||
_.each(fileInputs, function(fileInput) {
|
||||
var file = fileInput.files[0]
|
||||
size += file.size;
|
||||
})
|
||||
|
||||
if (size > fileTypeEnum) {
|
||||
return "<%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %>".strToErrorFormat();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any file exceeds allowed size limit
|
||||
var filesSizeValid = true;
|
||||
|
||||
// Check total size of uploaded files
|
||||
var totalSizeOK = checkFilesTotalSize(fileInputs);
|
||||
|
||||
_.each(fileInputs, function(fileInput) {
|
||||
var file = fileInput.files[0];
|
||||
var assetError = getFileTooBigError(file);
|
||||
var assetError = totalSizeOK;
|
||||
if (assetError) {
|
||||
renderFormError(ev, fileInput, assetError, false, "data-error='file-size'");
|
||||
filesSizeValid = false;
|
||||
|
|
|
@ -1441,6 +1441,7 @@ en:
|
|||
private: "private"
|
||||
search: "Search"
|
||||
file:
|
||||
total_size: "You can upload max %{size} MB of files at one time. Please remove one or more files and try to submit again."
|
||||
size_exceeded: "File size must be less than %{file_size} MB."
|
||||
blank: "You didn't select any file"
|
||||
uploading: "If you leave this page, the file(s) that is/are currently uploading will not be saved! Are you sure you want to continue?"
|
||||
|
|
Loading…
Reference in a new issue