diff options
Diffstat (limited to 'app/controllers/active_storage/variants_controller.rb')
-rw-r--r-- | app/controllers/active_storage/variants_controller.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/controllers/active_storage/variants_controller.rb b/app/controllers/active_storage/variants_controller.rb new file mode 100644 index 0000000000..dde7e1458f --- /dev/null +++ b/app/controllers/active_storage/variants_controller.rb @@ -0,0 +1,25 @@ +class ActiveStorage::VariantsController < ActionController::Base + def show + if blob_key = decode_verified_blob_key + redirect_to processed_variant_for(blob_key).url(disposition: disposition_param) + else + head :not_found + end + end + + private + def decode_verified_blob_key + ActiveStorage::VerifiedKeyWithExpiration.decode(params[:encoded_blob_key]) + end + + def processed_variant_for(blob_key) + ActiveStorage::Variant.new( + ActiveStorage::Blob.find_by!(key: blob_key), + ActiveStorage::Variation.decode(params[:variation_key]) + ).processed + end + + def disposition_param + params[:disposition].presence_in(%w( inline attachment )) || 'inline' + end +end |