From 0f302b897022b68793e102efa90a2819ff4e107a Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sat, 3 Mar 2018 21:36:43 +0100 Subject: Merge Previews/Variants controller into one Representations controller. Since ActiveStorage::Blob::Representable unifies the idea of previews and variants under one roof as representation, we may as well have the controllers follow suit. Thus ActiveStorage::RepresenationsController enters the fray. I've copied the old tests for both previews and variants and unified those as well. --- .../app/controllers/active_storage/previews_controller.rb | 10 ---------- .../active_storage/representations_controller.rb | 14 ++++++++++++++ .../app/controllers/active_storage/variants_controller.rb | 14 -------------- 3 files changed, 14 insertions(+), 24 deletions(-) delete mode 100644 activestorage/app/controllers/active_storage/previews_controller.rb create mode 100644 activestorage/app/controllers/active_storage/representations_controller.rb delete mode 100644 activestorage/app/controllers/active_storage/variants_controller.rb (limited to 'activestorage/app/controllers') diff --git a/activestorage/app/controllers/active_storage/previews_controller.rb b/activestorage/app/controllers/active_storage/previews_controller.rb deleted file mode 100644 index aa7ef58ca4..0000000000 --- a/activestorage/app/controllers/active_storage/previews_controller.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -class ActiveStorage::PreviewsController < ActionController::Base - include ActiveStorage::SetBlob - - def show - expires_in ActiveStorage::Blob.service.url_expires_in - redirect_to ActiveStorage::Preview.new(@blob, params[:variation_key]).processed.service_url(disposition: params[:disposition]) - end -end diff --git a/activestorage/app/controllers/active_storage/representations_controller.rb b/activestorage/app/controllers/active_storage/representations_controller.rb new file mode 100644 index 0000000000..e0e944dc9c --- /dev/null +++ b/activestorage/app/controllers/active_storage/representations_controller.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Take a signed permanent reference for a blob representation and turn it into an expiring service URL for download. +# Note: These URLs are publicly accessible. If you need to enforce access protection beyond the +# security-through-obscurity factor of the signed blob and variation reference, you'll need to implement your own +# authenticated redirection controller. +class ActiveStorage::RepresentationsController < ActionController::Base + include ActiveStorage::SetBlob + + def show + expires_in ActiveStorage::Blob.service.url_expires_in + redirect_to @blob.representation(params[:variation_key]).processed.service_url(disposition: params[:disposition]) + end +end diff --git a/activestorage/app/controllers/active_storage/variants_controller.rb b/activestorage/app/controllers/active_storage/variants_controller.rb deleted file mode 100644 index e8f8dd592d..0000000000 --- a/activestorage/app/controllers/active_storage/variants_controller.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -# Take a signed permanent reference for a variant and turn it into an expiring service URL for download. -# Note: These URLs are publicly accessible. If you need to enforce access protection beyond the -# security-through-obscurity factor of the signed blob and variation reference, you'll need to implement your own -# authenticated redirection controller. -class ActiveStorage::VariantsController < ActionController::Base - include ActiveStorage::SetBlob - - def show - expires_in ActiveStorage::Blob.service.url_expires_in - redirect_to ActiveStorage::Variant.new(@blob, params[:variation_key]).processed.service_url(disposition: params[:disposition]) - end -end -- cgit v1.2.3