diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-06 11:33:29 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-06 11:33:29 +0200 |
commit | c624df326a4ef36919a5195a3c5509fab97dcba3 (patch) | |
tree | a8e07aabde7548d5bd4a322a9898ad123cfa40f7 /lib/active_storage/disk_controller.rb | |
parent | 5869045f2e71f0abdf3add19629d23a46b9fff0d (diff) | |
download | rails-c624df326a4ef36919a5195a3c5509fab97dcba3.tar.gz rails-c624df326a4ef36919a5195a3c5509fab97dcba3.tar.bz2 rails-c624df326a4ef36919a5195a3c5509fab97dcba3.zip |
ActiveVault -> ActiveStorage
Yaroslav agreed to hand over the gem name ❤️
Diffstat (limited to 'lib/active_storage/disk_controller.rb')
-rw-r--r-- | lib/active_storage/disk_controller.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/active_storage/disk_controller.rb b/lib/active_storage/disk_controller.rb new file mode 100644 index 0000000000..3eba86c213 --- /dev/null +++ b/lib/active_storage/disk_controller.rb @@ -0,0 +1,28 @@ +require "action_controller" +require "active_storage/blob" +require "active_storage/verified_key_with_expiration" + +require "active_support/core_ext/object/inclusion" + +class ActiveStorage::DiskController < ActionController::Base + def show + if key = decode_verified_key + blob = ActiveStorage::Blob.find_by!(key: key) + + if stale?(etag: blob.checksum) + send_data blob.download, filename: blob.filename, type: blob.content_type, disposition: disposition_param + end + else + head :not_found + end + end + + private + def decode_verified_key + ActiveStorage::VerifiedKeyWithExpiration.decode(params[:encoded_key]) + end + + def disposition_param + params[:disposition].presence_in(%w( inline attachment )) || 'inline' + end +end |