From d30586211b41e018869a1a3f4e3af778a31591db Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Thu, 28 Sep 2017 16:43:37 -0400 Subject: Preview PDFs and videos --- activestorage/app/models/active_storage/variant.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activestorage/app/models/active_storage/variant.rb') diff --git a/activestorage/app/models/active_storage/variant.rb b/activestorage/app/models/active_storage/variant.rb index 02bf32b352..54685b4c0e 100644 --- a/activestorage/app/models/active_storage/variant.rb +++ b/activestorage/app/models/active_storage/variant.rb @@ -38,8 +38,8 @@ class ActiveStorage::Variant attr_reader :blob, :variation delegate :service, to: :blob - def initialize(blob, variation) - @blob, @variation = blob, variation + def initialize(blob, variation_or_variation_key) + @blob, @variation = blob, ActiveStorage::Variation.wrap(variation_or_variation_key) end # Returns the variant instance itself after it's been processed or an existing processing has been found on the service. @@ -61,7 +61,7 @@ class ActiveStorage::Variant # Use url_for(variant) (or the implied form, like +link_to variant+ or +redirect_to variant+) to get the stable URL # for a variant that points to the ActiveStorage::VariantsController, which in turn will use this +service_call+ method # for its redirection. - def service_url(expires_in: 5.minutes, disposition: :inline) + def service_url(expires_in: service.url_expires_in, disposition: :inline) service.url key, expires_in: expires_in, disposition: disposition, filename: blob.filename, content_type: blob.content_type end -- cgit v1.2.3 From ead60686e810df4b49bf19f4f113b48f16ae560f Mon Sep 17 00:00:00 2001 From: khall Date: Wed, 4 Oct 2017 12:26:04 -0700 Subject: Replace variation key use with SHA256 of key to prevent long filenames If a variant has a large set of options associated with it, the generated filename will be too long, causing Errno::ENAMETOOLONG to be raised. This change replaces those potentially long filenames with a much more compact SHA256 hash. Fixes #30662. --- activestorage/app/models/active_storage/variant.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activestorage/app/models/active_storage/variant.rb') diff --git a/activestorage/app/models/active_storage/variant.rb b/activestorage/app/models/active_storage/variant.rb index 54685b4c0e..90a3605331 100644 --- a/activestorage/app/models/active_storage/variant.rb +++ b/activestorage/app/models/active_storage/variant.rb @@ -50,7 +50,7 @@ class ActiveStorage::Variant # Returns a combination key of the blob and the variation that together identifies a specific variant. def key - "variants/#{blob.key}/#{variation.key}" + "variants/#{blob.key}/#{Digest::SHA256.hexdigest(variation.key)}" end # Returns the URL of the variant on the service. This URL is intended to be short-lived for security and not used directly -- cgit v1.2.3 From 445c682a8465b1a42f1335ae2cf7d20b9a112fcd Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Thu, 12 Oct 2017 11:47:21 -0400 Subject: Introduce ActiveStorage::Blob#representation --- activestorage/app/models/active_storage/variant.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activestorage/app/models/active_storage/variant.rb') diff --git a/activestorage/app/models/active_storage/variant.rb b/activestorage/app/models/active_storage/variant.rb index 90a3605331..915b78162c 100644 --- a/activestorage/app/models/active_storage/variant.rb +++ b/activestorage/app/models/active_storage/variant.rb @@ -65,6 +65,10 @@ class ActiveStorage::Variant service.url key, expires_in: expires_in, disposition: disposition, filename: blob.filename, content_type: blob.content_type end + # Returns the receiving variant. Allows ActiveStorage::Variant and ActiveStorage::Preview instances to be duck-typed. + def image + self + end private def processed? -- cgit v1.2.3 From 29da7d1ff510a9f376fc6c780273dfa89298ff51 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Fri, 13 Oct 2017 07:52:39 -0400 Subject: Clarify comment [ci skip] --- activestorage/app/models/active_storage/variant.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activestorage/app/models/active_storage/variant.rb') diff --git a/activestorage/app/models/active_storage/variant.rb b/activestorage/app/models/active_storage/variant.rb index 915b78162c..fa5aa69bd3 100644 --- a/activestorage/app/models/active_storage/variant.rb +++ b/activestorage/app/models/active_storage/variant.rb @@ -65,7 +65,7 @@ class ActiveStorage::Variant service.url key, expires_in: expires_in, disposition: disposition, filename: blob.filename, content_type: blob.content_type end - # Returns the receiving variant. Allows ActiveStorage::Variant and ActiveStorage::Preview instances to be duck-typed. + # Returns the receiving variant. Allows ActiveStorage::Variant and ActiveStorage::Preview instances to be used interchangeably. def image self end -- cgit v1.2.3