diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-20 17:34:13 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-20 17:34:13 -0500 |
commit | 1c85eecee02ebf0c0148de807fbb1a9e9573af8a (patch) | |
tree | 0d5548f150ae825210f7ba04d4bc9fee9d686fbc | |
parent | 1a9026b485b9b1da0f34c526d4c901406074c508 (diff) | |
download | rails-1c85eecee02ebf0c0148de807fbb1a9e9573af8a.tar.gz rails-1c85eecee02ebf0c0148de807fbb1a9e9573af8a.tar.bz2 rails-1c85eecee02ebf0c0148de807fbb1a9e9573af8a.zip |
Move controllers to default engine location for auto loading
-rw-r--r-- | Rakefile | 1 | ||||
-rw-r--r-- | app/controllers/active_storage/disk_controller.rb (renamed from lib/active_storage/disk_controller.rb) | 0 | ||||
-rw-r--r-- | app/controllers/active_storage/variants_controller.rb | 22 | ||||
-rw-r--r-- | lib/active_storage/direct_uploads_controller.rb | 14 |
4 files changed, 23 insertions, 14 deletions
@@ -3,6 +3,7 @@ require "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new do |test| + test.libs << "app/controllers" test.libs << "test" test.test_files = FileList["test/**/*_test.rb"] test.warning = false diff --git a/lib/active_storage/disk_controller.rb b/app/controllers/active_storage/disk_controller.rb index 16a295d00d..16a295d00d 100644 --- a/lib/active_storage/disk_controller.rb +++ b/app/controllers/active_storage/disk_controller.rb diff --git a/app/controllers/active_storage/variants_controller.rb b/app/controllers/active_storage/variants_controller.rb new file mode 100644 index 0000000000..05685dca17 --- /dev/null +++ b/app/controllers/active_storage/variants_controller.rb @@ -0,0 +1,22 @@ +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.find_or_process_by!(blob_key: blob_key, encoded_variant_key: params[:encoded_variant_key]) + end + + def disposition_param + params[:disposition].presence_in(%w( inline attachment )) || 'inline' + end +end diff --git a/lib/active_storage/direct_uploads_controller.rb b/lib/active_storage/direct_uploads_controller.rb deleted file mode 100644 index 99ff27f903..0000000000 --- a/lib/active_storage/direct_uploads_controller.rb +++ /dev/null @@ -1,14 +0,0 @@ -require "action_controller" -require "active_storage/blob" - -class ActiveStorage::DirectUploadsController < ActionController::Base - def create - blob = ActiveStorage::Blob.create_before_direct_upload!(blob_args) - render json: { url: blob.url_for_direct_upload, sgid: blob.to_sgid.to_param } - end - - private - def blob_args - params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, :metadata).to_h.symbolize_keys - end -end |