diff options
author | George Claghorn <george@basecamp.com> | 2018-03-05 11:53:31 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-03-05 11:54:43 -0500 |
commit | ccac681122db9747fec9512076772bca345e24b9 (patch) | |
tree | 9648be7aa60c62b44d74e898b7a9f9888e6d7789 /activestorage/app | |
parent | 9cc0c1aaf4d35b79055471f1a7ef0dba692b366d (diff) | |
download | rails-ccac681122db9747fec9512076772bca345e24b9.tar.gz rails-ccac681122db9747fec9512076772bca345e24b9.tar.bz2 rails-ccac681122db9747fec9512076772bca345e24b9.zip |
Generate root-relative paths in Active Storage disk service URL methods
Fixes #32129.
Diffstat (limited to 'activestorage/app')
-rw-r--r-- | activestorage/app/models/active_storage/blob/identifiable.rb | 10 | ||||
-rw-r--r-- | activestorage/app/models/active_storage/identification.rb | 35 |
2 files changed, 7 insertions, 38 deletions
diff --git a/activestorage/app/models/active_storage/blob/identifiable.rb b/activestorage/app/models/active_storage/blob/identifiable.rb index dbe03cfa6c..049e45dc3e 100644 --- a/activestorage/app/models/active_storage/blob/identifiable.rb +++ b/activestorage/app/models/active_storage/blob/identifiable.rb @@ -2,7 +2,7 @@ module ActiveStorage::Blob::Identifiable def identify - update!(content_type: identification.content_type, identified: true) unless identified? + update! content_type: identify_content_type, identified: true unless identified? end def identified? @@ -10,7 +10,11 @@ module ActiveStorage::Blob::Identifiable end private - def identification - ActiveStorage::Identification.new self + def identify_content_type + Marcel::MimeType.for download_identifiable_chunk, name: filename.to_s, declared_type: content_type + end + + def download_identifiable_chunk + service.download_chunk key, 0...4.kilobytes end end diff --git a/activestorage/app/models/active_storage/identification.rb b/activestorage/app/models/active_storage/identification.rb deleted file mode 100644 index 8d334ae1ea..0000000000 --- a/activestorage/app/models/active_storage/identification.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require "net/http" - -class ActiveStorage::Identification #:nodoc: - attr_reader :blob - - def initialize(blob) - @blob = blob - end - - def content_type - Marcel::MimeType.for(identifiable_chunk, name: filename, declared_type: declared_content_type) - end - - private - def identifiable_chunk - Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |client| - client.get(uri, "Range" => "bytes=0-4095").body - end - end - - def uri - @uri ||= URI.parse(blob.service_url) - end - - - def filename - blob.filename.to_s - end - - def declared_content_type - blob.content_type - end -end |