Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: new 'simultaneous_uploads' site setting

Régis Hanol0bf52d422c39
diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6
index 344da0f340a..1227e864b34 100644
--- a/app/assets/javascripts/discourse/components/composer-editor.js.es6
+++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6
@@ -618,7 +618,6 @@ export default Ember.Component.extend({
_bindUploadTarget() {
this._unbindUploadTarget(); // in case it's still bound, let's clean it up first
-
this._pasted = false;
const $element = this.$();
@@ -649,12 +648,23 @@ export default Ember.Component.extend({
});
$element.on("fileuploadsubmit", (e, data) => {
+ const max = this.siteSettings.simultaneous_uploads;
+
+ // Limit the number of simultaneous uploads
+ if (max > 0 && data.files.length > max) {
+ bootbox.alert(
+ I18n.t("post.errors.too_many_dragged_and_dropped_files", { max })
+ );
+ return false;
+ }
+
// Look for a matching file upload handler contributed from a plugin
const matcher = handler => {
const ext = handler.extensions.join("|");
const regex = new RegExp(`\\.(${ext})$`, "i");
return regex.test(data.files[0].name);
};
+
const matchingHandler = uploadHandlers.find(matcher);
if (data.files.length === 1 && matchingHandler) {
matchingHandler.method(data.files[0]);
diff --git a/app/assets/javascripts/discourse/mixins/upload.js.es6 b/app/assets/javascripts/discourse/mixins/upload.js.es6
index 6ff81b8ec05..d3e37021871 100644
--- a/app/assets/javascripts/discourse/mixins/upload.js.es6
+++ b/app/assets/javascripts/discourse/mixins/upload.js.es6
@@ -34,7 +34,10 @@ export default Em.Mixin.create({
const $upload = this.$();
const reset = () =>
this.setProperties({ uploading: false, uploadProgress: 0 });
- const maxFiles = this.getWithDefault("maxFiles", 10);
+ const maxFiles = this.getWithDefault(
+ "maxFiles",
+ this.siteSettings.simultaneous_uploads
+ );
$upload.on("fileuploaddone", (e, data) => {
let upload = data.result;
@@ -56,8 +59,12 @@ export default Em.Mixin.create({
);
$upload.on("fileuploaddrop", (e, data) => {
- if (data.files.length > maxFiles) {
- bootbox.alert(I18n.t("post.errors.too_many_dragged_and_dropped_files"));
+ if (maxFiles > 0 && data.files.length > maxFiles) {
+ bootbox.alert(
+ I18n.t("post.errors.too_many_dragged_and_dropped_files", {
+ max: maxFiles
+ })
+ );
return false;
} else {
return true;
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 334c31ba6ac..0b7f3f86a28 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2093,7 +2093,7 @@ en:
upload: "Sorry, there was an error uploading that file. Please try again."
file_too_large: "Sorry, that file is too big (maximum size is {{max_size_kb}}kb). Why not upload your large file to a cloud sharing service, then share the link?"
too_many_uploads: "Sorry, you can only upload one file at a time."
- too_many_dragged_and_dropped_files: "Sorry, you can only upload 10 files at a time."
+ too_many_dragged_and_dropped_files: "Sorry, you can only upload {{max}} files at a time."
upload_not_authorized: "Sorry, the file you are trying to upload is not authorized (authorized extensions: {{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."
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index a02fa2d5edd..409cac00777 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1470,6 +1470,8 @@ en:
min_ratio_to_crop: "Ratio used to crop tall images. Enter the result of width / height."
+ simultaneous_uploads: "Maximum number of files that can be dragged & dropped in the composer"
+
enable_flash_video_onebox: "Enable embedding of swf and flv (Adobe Flash) links in oneboxes. WARNING: may introduce security risks."
default_invitee_trust_level: "Default trust level (0-4) for invited users."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 1d04f5adb09..3c5e32d4610 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -1031,6 +1031,11 @@ files:
default: 0.45 # 90% of 18:9
min: 0
max: 1
+ simultaneous_uploads:
+ client: true
+ default: 5
+ min: 0
+ max: 20
trust:
default_trust_level: