From fb8eb8c0f94bcdc3bc3835a83a7c6b7dd207dc21 Mon Sep 17 00:00:00 2001 From: Philipp Rothmann Date: Wed, 12 Jul 2023 13:11:39 +0200 Subject: [PATCH] limit max upload file size --- app/javascript/application.js | 1 + app/javascript/trix-editor-overrides.js | 7 +++++++ config/locales/de.yml | 2 ++ config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ config/locales/fr.yml | 2 ++ config/locales/nl.yml | 2 ++ config/locales/tr.yml | 2 ++ 8 files changed, 20 insertions(+) create mode 100644 app/javascript/trix-editor-overrides.js diff --git a/app/javascript/application.js b/app/javascript/application.js index ed5cae66c..497c300bc 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1,3 +1,4 @@ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import "trix" import "@rails/actiontext" +import "./trix-editor-overrides" \ No newline at end of file diff --git a/app/javascript/trix-editor-overrides.js b/app/javascript/trix-editor-overrides.js new file mode 100644 index 000000000..64cecbefc --- /dev/null +++ b/app/javascript/trix-editor-overrides.js @@ -0,0 +1,7 @@ +// app/javascript/trix-editor-overrides.js +window.addEventListener("trix-file-accept", function(event) { + if (event.file.size > 1024 * 1024 * 512) { + event.preventDefault() + alert(I18n.t('js.trix_editor.file_size_alert')) + } +}) \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index 10dffb81d..b7f77c5de 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1216,6 +1216,8 @@ de: js: ordering: confirm_change: Änderungen an dieser Bestellung gehen verloren, wenn zu einer anderen Bestellung gewechselt wird. Möchtest Du trotzdem wechseln? + trix_editor: + file_size_alert: Der Dateianhang ist zu groß! Die maximale Größe beträgt 512Mb layouts: email: footer_1_separator: "--" diff --git a/config/locales/en.yml b/config/locales/en.yml index 316566f30..b4f41c5cd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1219,6 +1219,8 @@ en: js: ordering: confirm_change: Modifications to this order will be lost when you change the order. Do you want to lose the changes you made and continue? + trix_editor: + file_size_alert: The file is to large! The supported file size is 512Mb! layouts: email: footer_1_separator: "--" diff --git a/config/locales/es.yml b/config/locales/es.yml index dba6859ec..6cacb5641 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1080,6 +1080,8 @@ es: js: ordering: confirm_change: Las modificaciones sobre este pedido se perderán cuando cambies el pedido. ¿Quieres perder los cambios que has hecho y continuar? + trix_editor: + file_size_alert: ¡El archivo adjunto es demasiado grande! El tamaño máximo es de 512Mb layouts: email: footer_4_help: 'Ayuda: %{url}' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 26f2f62cc..cd0971da9 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -831,6 +831,8 @@ fr: js: ordering: confirm_change: Les changements apportés à cette commande vont être perdus. Est-ce que tu veux vraiment continuer? + trix_editor: + file_size_alert: Le fichier joint est trop volumineux ! La taille maximale est de 512Mb layouts: email: footer_3_homepage: 'Boufcoop: %{url}' diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 304254cbe..d972c088c 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -1189,6 +1189,8 @@ nl: js: ordering: confirm_change: Als je naar een andere bestelling gaat, gaan je aanpassingen in deze bestelling verloren. Wijzigingen vergeten en naar de andere bestelling gaan? + trix_editor: + file_size_alert: De bestandsbijlage is te groot! De maximale grootte is 512Mb! layouts: email: footer_1_separator: "--" diff --git a/config/locales/tr.yml b/config/locales/tr.yml index b66d5c06a..76408463f 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -1218,6 +1218,8 @@ tr: js: ordering: confirm_change: Bu siparişe yapılan değişiklikler kaybolacak. Değişikliklerinizi kaybetmek ve devam etmek istiyor musunuz? + trix_editor: + file_size_alert: Dosya eki çok büyük! Maksimum boyut 512Mb layouts: email: footer_1_separator: "--"