From 628a5fedb284d5624ae3efe13de7ba831c8d223f Mon Sep 17 00:00:00 2001 From: maki Date: Thu, 6 Jun 2024 16:16:52 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20m=C3=A9todos=20en=20disk=5Fcontroller?= =?UTF-8?q?=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