cloudinary 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e13d4a9d8701f1b37bfa34a12f4d393390a2d61ee0a351edb35c662f347ef2f
4
- data.tar.gz: d818c41861f532a8cc991d8bba70fc3bf29ae3fcbe0e769efec86a4457767045
3
+ metadata.gz: 4f827756d17fc0b871d277a5bbdc6bc1ab3edeb30cf8765f29dd9fda17f6870d
4
+ data.tar.gz: 91e533b452f021f65255e26caed2271d5a96387a5c5728f5268720c9a2306fb6
5
5
  SHA512:
6
- metadata.gz: c32eab5d9184adb7063bbd5f5b1a9e728ded397b76834bceaa331faf9d3429e4ad45bf7493aa4e3ceedcdf33eba21b4354fbd7173bcd7c3727382d9b5b43793e
7
- data.tar.gz: 28c275bc3ae56751653ceefca9cbd81609ee9894cac57ee259ded5083ca94c64a2936196fd5bff92e1cd09c91275edce33b98e0fcf9edf903d2c70ad6fa1ad6d
6
+ metadata.gz: 837eb7160f55eed0b1df45d041c2a8deb18ccd0acd6ee405cf70f151ee7926bf5715bd9852f7da21ef393a28e8ad630d40770d47ed7b296c915a98dd5fb8f417
7
+ data.tar.gz: a724d55a25e2b09a33d2c722021ad3c335a034e822961f86312916b6296902d1b65417ae0f630537fa10f603cf7ff28f98b291f648777d371d578524a0062ba9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ 2.2.0 / 2024-09-08
2
+ ==================
3
+
4
+ New functionality and features
5
+ ------------------------------
6
+
7
+ * Add support for ActiveStorage model service configuration
8
+
9
+ Other Changes
10
+ -------------
11
+
12
+ * Fix asset type detection in ActiveStorage
13
+ * Add explicit `ostruct` dependency
14
+
1
15
  2.1.2 / 2024-08-18
2
16
  ==================
3
17
 
data/cloudinary.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_dependency "faraday", ">= 2.0.1", "< 3.0.0"
28
28
  s.add_dependency "faraday-multipart", "~> 1.0", ">= 1.0.4"
29
29
  s.add_dependency 'faraday-follow_redirects', '~> 0.3.0'
30
+ s.add_dependency "ostruct"
30
31
 
31
32
  s.add_development_dependency "rails", ">= 6.1.7", "< 8.0.0"
32
33
  s.add_development_dependency "rexml", ">= 3.2.5", "< 4.0.0"
@@ -17,9 +17,13 @@ module CloudinaryHelper
17
17
  alias cloudinary_url_internal_original cloudinary_url_internal
18
18
 
19
19
  def cloudinary_url_internal(source, options = {})
20
- if defined?(ActiveStorage::Blob.service.public_id) && options.fetch(:type, "").to_s != "fetch"
21
- source = ActiveStorage::Blob.service.public_id(source)
20
+ service_instance, options = ActiveStorage::Service::CloudinaryService.fetch_service_instance_and_config(source, options)
21
+ service_instance ||= ActiveStorage::Blob.service
22
+
23
+ if defined?(service_instance.public_id) && options.fetch(:type, "").to_s != "fetch"
24
+ source = service_instance.public_id(source)
22
25
  end
26
+
23
27
  cloudinary_url_internal_original(source, options)
24
28
  end
25
29
  end
@@ -58,6 +62,7 @@ module ActiveStorage
58
62
  end
59
63
 
60
64
  def url(key, filename: nil, content_type: '', **options)
65
+ key = find_blob_or_use_key(key)
61
66
  instrument :url, key: key do |payload|
62
67
  url = Cloudinary::Utils.cloudinary_url(
63
68
  full_public_id_internal(key, options),
@@ -101,6 +106,7 @@ module ActiveStorage
101
106
  end
102
107
 
103
108
  def delete(key)
109
+ key = find_blob_or_use_key(key)
104
110
  instrument :delete, key: key do
105
111
  options = {
106
112
  resource_type: resource_type(nil, key),
@@ -117,6 +123,7 @@ module ActiveStorage
117
123
  end
118
124
 
119
125
  def exist?(key)
126
+ key = find_blob_or_use_key(key)
120
127
  instrument :exist, key: key do |payload|
121
128
  begin
122
129
  options = {
@@ -153,8 +160,7 @@ module ActiveStorage
153
160
 
154
161
  # Return the partial content in the byte +range+ of the file at the +key+.
155
162
  def download_chunk(key, range)
156
- url = Cloudinary::Utils.cloudinary_url(public_id(key), resource_type: resource_type(nil, key))
157
- uri = URI(url)
163
+ uri = URI(url(key))
158
164
  instrument :download, key: key do
159
165
  req = Net::HTTP::Get.new(uri)
160
166
  range_end = case
@@ -190,6 +196,33 @@ module ActiveStorage
190
196
  full_public_id_internal(public_id)
191
197
  end
192
198
 
199
+ def self.fetch_service_instance_and_config(source, options)
200
+ return [nil, options] unless defined?(ActiveStorage::BlobKey) && source.is_a?(ActiveStorage::BlobKey) &&
201
+ source.respond_to?(:attributes) && source.attributes.key?(:service_name)
202
+
203
+ service_name = source.attributes[:service_name]
204
+
205
+ begin
206
+ service_instance = ActiveStorage::Blob.services.fetch(service_name.to_sym)
207
+
208
+ unless service_instance.instance_of?(ActiveStorage::Service::CloudinaryService)
209
+ Rails.logger.error "Expected service instance #{service_instance.class.name} to be of type ActiveStorage::Service::CloudinaryService."
210
+ return [nil, options]
211
+ end
212
+
213
+ service_config = Rails.application.config.active_storage.service_configurations.fetch(service_name)
214
+ options = service_config.merge(options)
215
+ rescue NameError => e
216
+ Rails.logger.error "Failed to retrieve the service instance for #{service_name}: #{e.message}"
217
+ return [nil, options]
218
+ rescue => e
219
+ Rails.logger.error "An unexpected error occurred: #{e.message}"
220
+ return [nil, options]
221
+ end
222
+
223
+ [service_instance, options]
224
+ end
225
+
193
226
  private
194
227
 
195
228
  def api_uri(action, options)
@@ -278,5 +311,19 @@ module ActiveStorage
278
311
  end
279
312
  content_type_to_resource_type(content_type)
280
313
  end
314
+
315
+ def find_blob_or_use_key(key)
316
+ if key.is_a?(ActiveStorage::BlobKey)
317
+ key
318
+ else
319
+ begin
320
+ blob = ActiveStorage::Blob.find_by(key: key)
321
+ blob ? ActiveStorage::BlobKey.new(blob.attributes.as_json) : key
322
+ rescue ActiveRecord::StatementInvalid => e
323
+ # Return the original key if an error occurs
324
+ key
325
+ end
326
+ end
327
+ end
281
328
  end
282
329
  end
@@ -1,4 +1,4 @@
1
1
  # Copyright Cloudinary
2
2
  module Cloudinary
3
- VERSION = "2.1.2"
3
+ VERSION = "2.2.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudinary
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nadav Soferman
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-08-18 00:00:00.000000000 Z
13
+ date: 2024-09-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: ostruct
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rails
71
85
  requirement: !ruby/object:Gem::Requirement