aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxed.co>2018-03-26 14:36:39 +0100
committerAndrew White <andrew.white@unboxed.co>2018-04-06 20:07:52 +0100
commit9436c22e2aa9419f275186967a1b863bc3d01ecb (patch)
tree3a833e8e5f773d0f6668b44d15bceb644db932a3 /activestorage/lib
parent03bd370c02a8fa83ab6dd01bdd99fe342c523b81 (diff)
downloadrails-9436c22e2aa9419f275186967a1b863bc3d01ecb.tar.gz
rails-9436c22e2aa9419f275186967a1b863bc3d01ecb.tar.bz2
rails-9436c22e2aa9419f275186967a1b863bc3d01ecb.zip
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).
Diffstat (limited to 'activestorage/lib')
-rw-r--r--activestorage/lib/active_storage/service/disk_service.rb11
1 files changed, 7 insertions, 4 deletions
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