mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
FEATURE: prevent upload of more than 10 files at a time
This commit is contained in:
parent
38fbdf65ef
commit
db53e022cc
|
@ -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() &&
|
||||
|
|
|
@ -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') };
|
||||
|
|
|
@ -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."
|
||||
|
|
Loading…
Reference in New Issue
Block a user