mirror of
https://0xacab.org/sutty/sutty
synced 2025-03-14 17:08:21 +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:
commit
d7a19ed3a7
2 changed files with 30 additions and 3 deletions
|
@ -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
|
||||||
|
@ -55,6 +55,14 @@ module ActiveStorage
|
||||||
rescue ActiveStorage::IntegrityError
|
rescue ActiveStorage::IntegrityError
|
||||||
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
|
||||||
|
|
||||||
|
@ -64,7 +72,23 @@ module ActiveStorage
|
||||||
|
|
||||||
def page_not_found(exception)
|
def page_not_found(exception)
|
||||||
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
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
|
@ -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'
|
||||||
|
|
Loading…
Reference in a new issue