diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-23 11:05:20 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-23 11:05:20 -0500 |
commit | 46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea (patch) | |
tree | bc19d2f900055e39de21f62ec27e9079723cfa5f /app/controllers | |
parent | 8f20624820ed0922b33fceb4013d3ff11015b366 (diff) | |
download | rails-46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea.tar.gz rails-46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea.tar.bz2 rails-46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea.zip |
Switch to simpler signed_id for blob rather than full GlobalID
We don't need to lookup multiple different classes, so no need to use a globalid.
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/active_storage/direct_uploads_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/active_storage/variants_controller.rb | 17 |
2 files changed, 12 insertions, 10 deletions
diff --git a/app/controllers/active_storage/direct_uploads_controller.rb b/app/controllers/active_storage/direct_uploads_controller.rb index dccd864e8d..0d1b806f9f 100644 --- a/app/controllers/active_storage/direct_uploads_controller.rb +++ b/app/controllers/active_storage/direct_uploads_controller.rb @@ -1,7 +1,10 @@ +# Creates a new blob on the server side in anticipation of a direct-to-service upload from the client side. +# When the client-side upload is completed, the signed_blob_id can be submitted as part of the form to reference +# the blob that was created up front. 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 } + render json: { upload_to_url: blob.url_for_direct_upload, signed_blob_id: blob.signed_id } end private diff --git a/app/controllers/active_storage/variants_controller.rb b/app/controllers/active_storage/variants_controller.rb index d5e97e63fa..a65d7d7571 100644 --- a/app/controllers/active_storage/variants_controller.rb +++ b/app/controllers/active_storage/variants_controller.rb @@ -1,22 +1,21 @@ +require "active_storage/variant" + 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) + if blob = find_signed_blob + redirect_to ActiveStorage::Variant.new(blob, decoded_variation).processed.url(disposition: disposition_param) else head :not_found end end private - def decode_verified_blob_key - ActiveStorage::VerifiedKeyWithExpiration.decode(params[:encoded_blob_key]) + def find_signed_blob + ActiveStorage::Blob.find_signed(params[:signed_blob_id]) end - def processed_variant_for(blob_key) - ActiveStorage::Variant.new( - ActiveStorage::Blob.find_by!(key: blob_key), - ActiveStorage::Variation.decode(params[:variation_key]) - ).processed + def decoded_variation + ActiveStorage::Variation.decode(params[:variation_key]) end def disposition_param |