5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2025-03-14 20:08:19 +00:00

Merge branch 'issue-102' into 'rails'

feat: métodos en disk_controller_decorator #102

See merge request sutty/sutty!271
This commit is contained in:
Maki 2025-01-25 11:44:11 +00:00
commit d7a19ed3a7
2 changed files with 30 additions and 3 deletions

View file

@ -11,7 +11,7 @@ module ActiveStorage
# Permitir incrustar archivos subidos (especialmente PDFs) desde # Permitir incrustar archivos subidos (especialmente PDFs) desde
# otros sitios. # otros sitios.
def show def show
original_show.tap do |s| original_show.tap do |_|
response.headers.delete 'X-Frame-Options' response.headers.delete 'X-Frame-Options'
end end
end end
@ -29,7 +29,7 @@ module ActiveStorage
if remote_file?(token) if remote_file?(token)
begin begin
url = request.body.read 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 checksum = Digest::MD5.file(body.path).base64digest
blob.metadata[:url] = url blob.metadata[:url] = url
blob.update_columns checksum: checksum, byte_size: body.size, metadata: blob.metadata blob.update_columns checksum: checksum, byte_size: body.size, metadata: blob.metadata
@ -56,6 +56,14 @@ module ActiveStorage
head :unprocessable_entity head :unprocessable_entity
end end
# 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.
def limits
ruby_hash = { max_upload_size: max_upload_size, max_download_size: max_download_size }
render json: ruby_hash
end
private private
def remote_file?(token) def remote_file?(token)
@ -66,6 +74,22 @@ module ActiveStorage
head :not_found head :not_found
ExceptionNotifier.notify_exception(exception, data: { params: params.to_hash }) ExceptionNotifier.notify_exception(exception, data: { params: params.to_hash })
end 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.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.fetch('MAX_DOWNLOAD_SIZE', '111').to_i.megabytes
end
end end
end end
end end

View file

@ -116,6 +116,9 @@ Rails.application.routes.draw do
get 'i18n/edit', to: 'i18n#edit' get 'i18n/edit', to: 'i18n#edit'
post 'i18n', to: 'i18n#update' post 'i18n', to: 'i18n#update'
# Ver límites de tamaño de archivos
get 'limits', to: 'sites#limits'
# Compilar el sitio # Compilar el sitio
post 'enqueue', to: 'sites#enqueue' post 'enqueue', to: 'sites#enqueue'
post 'reorder_posts', to: 'sites#reorder_posts' post 'reorder_posts', to: 'sites#reorder_posts'