From 628a5fedb284d5624ae3efe13de7ba831c8d223f Mon Sep 17 00:00:00 2001 From: maki Date: Thu, 6 Jun 2024 16:16:52 -0300 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20m=C3=A9todos=20en=20disk=5Fcontroll?= =?UTF-8?q?er=5Fdecorator=20#102?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../active_storage/disk_controller_decorator.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/active_storage/disk_controller_decorator.rb b/app/controllers/active_storage/disk_controller_decorator.rb index ec3ac0b4..07a166c3 100644 --- a/app/controllers/active_storage/disk_controller_decorator.rb +++ b/app/controllers/active_storage/disk_controller_decorator.rb @@ -29,7 +29,7 @@ module ActiveStorage if remote_file?(token) begin url = request.body.read - body = Down.download(url, max_size: 111.megabytes) + body = Down.download(url, max_size: max_download_size) checksum = Digest::MD5.file(body.path).base64digest blob.metadata[:url] = url blob.update_columns checksum: checksum, byte_size: body.size, metadata: blob.metadata @@ -56,6 +56,11 @@ module ActiveStorage head :unprocessable_entity end + def limits(max_upload_size, max_download_size) + ruby_hash = { "max_upload_size": max_upload_size, "max_download_size": max_download_size } + json_string = JSON.generate(ruby_hash) + end + private def remote_file?(token) @@ -66,6 +71,14 @@ module ActiveStorage head :not_found ExceptionNotifier.notify_exception(exception, data: {params: params.to_hash}) end + + def max_upload_size + max_upload_size_mbs = ENV['MAX_UPLOAD_SIZE'].to_i.megabytes + end + + def max_download_size + max_download_size_mbs = ENV['MAX_DOWNLOAD_SIZE'].to_i.megabytes + end end end end From 83b29bbd8ae208ee341e41b1c8d2dd661ad19c11 Mon Sep 17 00:00:00 2001 From: maki Date: Thu, 6 Jun 2024 16:24:16 -0300 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20m=C3=A9todos=20en=20disk=5Fcontrolle?= =?UTF-8?q?r=5Fdecorator.rb=20#102?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../active_storage/disk_controller_decorator.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/active_storage/disk_controller_decorator.rb b/app/controllers/active_storage/disk_controller_decorator.rb index 07a166c3..0364efa9 100644 --- a/app/controllers/active_storage/disk_controller_decorator.rb +++ b/app/controllers/active_storage/disk_controller_decorator.rb @@ -11,7 +11,7 @@ module ActiveStorage # Permitir incrustar archivos subidos (especialmente PDFs) desde # otros sitios. def show - original_show.tap do |s| + original_show.tap do |_s| response.headers.delete 'X-Frame-Options' end end @@ -57,7 +57,7 @@ module ActiveStorage end def limits(max_upload_size, max_download_size) - ruby_hash = { "max_upload_size": max_upload_size, "max_download_size": max_download_size } + ruby_hash = { max_upload_size: max_upload_size, max_download_size: max_download_size } json_string = JSON.generate(ruby_hash) end @@ -69,15 +69,15 @@ module ActiveStorage def page_not_found(exception) head :not_found - ExceptionNotifier.notify_exception(exception, data: {params: params.to_hash}) + ExceptionNotifier.notify_exception(exception, data: { params: params.to_hash }) end def max_upload_size - max_upload_size_mbs = ENV['MAX_UPLOAD_SIZE'].to_i.megabytes + ENV['MAX_UPLOAD_SIZE'].to_i.megabytes end def max_download_size - max_download_size_mbs = ENV['MAX_DOWNLOAD_SIZE'].to_i.megabytes + ENV['MAX_DOWNLOAD_SIZE'].to_i.megabytes end end end From c781aa3cd210a2bad7b179002bc5e78aa5b8df58 Mon Sep 17 00:00:00 2001 From: maki Date: Thu, 6 Jun 2024 16:25:43 -0300 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20m=C3=A9todos=20disk=5Fcontroller=5Fd?= =?UTF-8?q?ecorator.rb=20#102?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/active_storage/disk_controller_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/active_storage/disk_controller_decorator.rb b/app/controllers/active_storage/disk_controller_decorator.rb index 0364efa9..295913bc 100644 --- a/app/controllers/active_storage/disk_controller_decorator.rb +++ b/app/controllers/active_storage/disk_controller_decorator.rb @@ -58,7 +58,7 @@ module ActiveStorage def limits(max_upload_size, max_download_size) ruby_hash = { max_upload_size: max_upload_size, max_download_size: max_download_size } - json_string = JSON.generate(ruby_hash) + JSON.generate(ruby_hash) end private From fb2149d51f332faaf0b21d72c50f9ad8fa412a94 Mon Sep 17 00:00:00 2001 From: maki Date: Fri, 7 Jun 2024 13:54:28 -0300 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20documentaci=C3=B3n,=20valores=20por?= =?UTF-8?q?=20defecto=20y=20ruta=20en=20routes.rb=20#102?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../disk_controller_decorator.rb | 25 ++++++++++++++----- config/routes.rb | 3 +++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/controllers/active_storage/disk_controller_decorator.rb b/app/controllers/active_storage/disk_controller_decorator.rb index 295913bc..36afcd49 100644 --- a/app/controllers/active_storage/disk_controller_decorator.rb +++ b/app/controllers/active_storage/disk_controller_decorator.rb @@ -11,7 +11,7 @@ module ActiveStorage # Permitir incrustar archivos subidos (especialmente PDFs) desde # otros sitios. def show - original_show.tap do |_s| + original_show.tap do |_| response.headers.delete 'X-Frame-Options' end end @@ -55,10 +55,15 @@ module ActiveStorage rescue ActiveStorage::IntegrityError head :unprocessable_entity end - - def limits(max_upload_size, max_download_size) + + # Define una ruta que lleva a un JSON con los valores de los tamaños + # máximos de subida y descarga (respectivamente) que puede tener un + # archivo. + # + # @return [Integer] tamaño de subida que puede tener un archivo expresado en megabytes. + def limits ruby_hash = { max_upload_size: max_upload_size, max_download_size: max_download_size } - JSON.generate(ruby_hash) + render json: ruby_hash end private @@ -72,12 +77,20 @@ module ActiveStorage ExceptionNotifier.notify_exception(exception, data: { params: params.to_hash }) end + # Convierte a la variable de entorno que define el máximo tamaño de subida que puede tener un archivo + # en un entero expresado en megabytes. + # + # @return [Integer] tamaño máximo de subida que puede tener un archivo, expresado en megabytes. def max_upload_size - ENV['MAX_UPLOAD_SIZE'].to_i.megabytes + ENV.fetch('MAX_UPLOAD_SIZE', '111').to_i.megabytes end + # Convierte a la variable de entorno que define el máximo tamaño de descarga que puede tener un archivo + # en un entero expresado en megabytes. + # + # @return [Integer] tamaño máximo de descarga que puede tener un archivo, expresado en megabytes. def max_download_size - ENV['MAX_DOWNLOAD_SIZE'].to_i.megabytes + ENV.fetch('MAX_DOWNLOAD_SIZE', '111').to_i.megabytes end end end diff --git a/config/routes.rb b/config/routes.rb index 9d5c974a..f4371624 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,6 +111,9 @@ Rails.application.routes.draw do get 'i18n/edit', to: 'i18n#edit' post 'i18n', to: 'i18n#update' + # Ver límites de tamaño de archivos + get 'limits', to: 'limits' + # Compilar el sitio post 'enqueue', to: 'sites#enqueue' post 'reorder_posts', to: 'sites#reorder_posts' From 14373613febd7503f484fcbdeb8ca9cecc737208 Mon Sep 17 00:00:00 2001 From: maki Date: Tue, 18 Jun 2024 11:49:04 -0300 Subject: [PATCH 5/5] fix: ajustes #102 --- app/controllers/active_storage/disk_controller_decorator.rb | 2 -- config/routes.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/active_storage/disk_controller_decorator.rb b/app/controllers/active_storage/disk_controller_decorator.rb index 36afcd49..b4d8ef4f 100644 --- a/app/controllers/active_storage/disk_controller_decorator.rb +++ b/app/controllers/active_storage/disk_controller_decorator.rb @@ -59,8 +59,6 @@ module ActiveStorage # Define una ruta que lleva a un JSON con los valores de los tamaños # máximos de subida y descarga (respectivamente) que puede tener un # archivo. - # - # @return [Integer] tamaño de subida que puede tener un archivo expresado en megabytes. def limits ruby_hash = { max_upload_size: max_upload_size, max_download_size: max_download_size } render json: ruby_hash diff --git a/config/routes.rb b/config/routes.rb index f4371624..253210d0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,7 +112,7 @@ Rails.application.routes.draw do post 'i18n', to: 'i18n#update' # Ver límites de tamaño de archivos - get 'limits', to: 'limits' + get 'limits', to: 'sites#limits' # Compilar el sitio post 'enqueue', to: 'sites#enqueue'