5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-15 23:11:41 +00:00

feat: descargar archivos remotos sutty/editor#62

This commit is contained in:
f 2023-03-31 17:21:50 -03:00
parent 465d12a7f9
commit 5bdcaef738

View file

@ -21,11 +21,26 @@ module ActiveStorage
def update
if (token = decode_verified_token)
if acceptable_content?(token)
named_disk_service(token[:service_name]).upload token[:key], request.body, checksum: token[:checksum]
blob = ActiveStorage::Blob.find_by_key token[:key]
site = Site.find_by_name token[:service_name]
if remote_file?(token)
begin
url = request.body.read
body = Down.download(url, max_size: 111.megabytes)
checksum = nil
rescue StandardError => e
ExceptionNotifier.notify_exception(e, data: { key: token[:key], url: url, site: site.name })
head :content_too_large
end
else
body = request.body
checksum = token[:checksum]
end
named_disk_service(token[:service_name]).upload token[:key], body, checksum: checksum
site.static_files.attach(blob)
else
head :unprocessable_entity
@ -36,6 +51,12 @@ module ActiveStorage
rescue ActiveStorage::IntegrityError
head :unprocessable_entity
end
private
def remote_file?(token)
token[:content_type] == 'sutty/download-from-url'
end
end
end
end