aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_storage/controllers
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2017-07-11 18:53:17 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2017-07-11 18:53:17 +0200
commit1966c188cfb06b39a47082e2f6c6e33a43668ae5 (patch)
treeda96a28a10f331a38eb88a8b033f24bf38948d1e /lib/active_storage/controllers
parent9cf33478991b9fab663d5502342729b98eafa2bd (diff)
downloadrails-1966c188cfb06b39a47082e2f6c6e33a43668ae5.tar.gz
rails-1966c188cfb06b39a47082e2f6c6e33a43668ae5.tar.bz2
rails-1966c188cfb06b39a47082e2f6c6e33a43668ae5.zip
Very incomplete first stab
Diffstat (limited to 'lib/active_storage/controllers')
-rw-r--r--lib/active_storage/controllers/variants_controller.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/active_storage/controllers/variants_controller.rb b/lib/active_storage/controllers/variants_controller.rb
new file mode 100644
index 0000000000..24cee16e80
--- /dev/null
+++ b/lib/active_storage/controllers/variants_controller.rb
@@ -0,0 +1,22 @@
+require "action_controller"
+require "active_storage/blob"
+
+class ActiveStorage::Controllers::VariantsController < ActionController::Base
+ def show
+ if blob_key = decode_verified_key
+ variant = ActiveStorage::Variant.lookup(blob_key: blob_key, variation_key: params[:variation_key])
+ redirect_to variant.url
+ 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