diff --git a/app/controllers/active_storage/disk_controller_decorator.rb b/app/controllers/active_storage/disk_controller_decorator.rb index 0634a2ec..e49c22f1 100644 --- a/app/controllers/active_storage/disk_controller_decorator.rb +++ b/app/controllers/active_storage/disk_controller_decorator.rb @@ -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