FEATURE: prevent upload of more than 10 files at a time

This commit is contained in:
Régis Hanol 2015-02-11 19:34:48 +01:00
parent 38fbdf65ef
commit db53e022cc
3 changed files with 10 additions and 16 deletions

View File

@ -146,16 +146,9 @@ Discourse.Utilities = {
}
},
/**
Validate a list of files to be uploaded
@method validateUploadedFiles
@param {Array} files The list of files we want to upload
**/
validateUploadedFiles: function(files, bypassNewUserRestriction) {
if (!files || files.length === 0) { return false; }
// can only upload one file at a time
if (files.length > 1) {
bootbox.alert(I18n.t('post.errors.too_many_uploads'));
return false;
@ -173,15 +166,6 @@ Discourse.Utilities = {
return Discourse.Utilities.validateUploadedFile(upload, type, bypassNewUserRestriction);
},
/**
Validate a file to be uploaded
@method validateUploadedFile
@param {File} file The file to be uploaded
@param {string} type The type of the upload (image, attachment)
@params {bool} bypassNewUserRestriction
@returns true whenever the upload is valid
**/
validateUploadedFile: function(file, type, bypassNewUserRestriction) {
// check that the uploaded file is authorized
if (!Discourse.Utilities.authorizesAllExtensions() &&

View File

@ -22,6 +22,15 @@ export default Em.Mixin.create({
pasteZone: $upload
});
$upload.on("fileuploaddrop", function (e, data) {
if (data.files.length > 10) {
bootbox.alert(I18n.t("post.errors.too_many_dragged_and_dropped_files"));
return false;
} else {
return true;
}
});
$upload.on('fileuploadsubmit', function (e, data) {
var isValid = Discourse.Utilities.validateUploadedFiles(data.files, true);
var form = { image_type: self.get('type') };

View File

@ -1106,6 +1106,7 @@ en:
attachment_too_large: "Sorry, the file you are trying to upload is too big (maximum size is {{max_size_kb}}kb)."
file_too_large: "Sorry, the file you are trying to upload is too big (maximum size is {{max_size_kb}}kb)"
too_many_uploads: "Sorry, you can only upload one file at a time."
too_many_dragged_and_dropped_files: "Sorry, you can only drag & drop up to 10 files at a time."
upload_not_authorized: "Sorry, the file you are trying to upload is not authorized (authorized extension: {{authorized_extensions}})."
image_upload_not_allowed_for_new_user: "Sorry, new users can not upload images."
attachment_upload_not_allowed_for_new_user: "Sorry, new users can not upload attachments."