From 9436c22e2aa9419f275186967a1b863bc3d01ecb Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 26 Mar 2018 14:36:39 +0100 Subject: Use a current model to provide the host for service urls Trying to pass the current request down to the service so that it can create full urls instead of paths makes the API messy so use a model based on ActiveSupport::CurrentAttributes to provide the current host to services that need it (primarily the disk service). --- activestorage/lib/active_storage/service/disk_service.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'activestorage/lib') diff --git a/activestorage/lib/active_storage/service/disk_service.rb b/activestorage/lib/active_storage/service/disk_service.rb index 75b66081c3..5b652fe74e 100644 --- a/activestorage/lib/active_storage/service/disk_service.rb +++ b/activestorage/lib/active_storage/service/disk_service.rb @@ -78,8 +78,9 @@ module ActiveStorage verified_key_with_expiration = ActiveStorage.verifier.generate(key, expires_in: expires_in, purpose: :blob_key) generated_url = - url_helpers.rails_disk_service_path( + url_helpers.rails_disk_service_url( verified_key_with_expiration, + host: current_host, filename: filename, disposition: content_disposition_with(type: disposition, filename: filename), content_type: content_type @@ -104,7 +105,7 @@ module ActiveStorage purpose: :blob_token } ) - generated_url = url_helpers.update_rails_disk_service_path(verified_token_with_expiration) + generated_url = url_helpers.update_rails_disk_service_url(verified_token_with_expiration, host: current_host) payload[:url] = generated_url @@ -129,7 +130,6 @@ module ActiveStorage path_for(key).tap { |path| FileUtils.mkdir_p File.dirname(path) } end - def ensure_integrity_of(key, checksum) unless Digest::MD5.file(path_for(key)).base64digest == checksum delete key @@ -137,9 +137,12 @@ module ActiveStorage end end - def url_helpers @url_helpers ||= Rails.application.routes.url_helpers end + + def current_host + ActiveStorage::Current.host + end end end -- cgit v1.2.3