cloudinary 1.0.35 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,13 +6,12 @@ require 'cloudinary/carrier_wave/preloaded'
|
|
6
6
|
require 'cloudinary/carrier_wave/storage'
|
7
7
|
|
8
8
|
module Cloudinary::CarrierWave
|
9
|
-
|
9
|
+
|
10
10
|
def self.included(base)
|
11
11
|
base.storage Cloudinary::CarrierWave::Storage
|
12
12
|
base.extend ClassMethods
|
13
|
-
base.
|
13
|
+
base.class_attribute :storage_type, :metadata
|
14
14
|
base.send(:attr_reader, :stored_version)
|
15
|
-
|
16
15
|
override_in_versions(base, :blank?, :full_public_id, :all_versions_processors)
|
17
16
|
end
|
18
17
|
|
@@ -31,7 +30,7 @@ module Cloudinary::CarrierWave
|
|
31
30
|
self.original_filename = sanitize(@file.filename)
|
32
31
|
end
|
33
32
|
end
|
34
|
-
|
33
|
+
|
35
34
|
def url(*args)
|
36
35
|
if args.first && !args.first.is_a?(Hash)
|
37
36
|
super
|
@@ -46,7 +45,13 @@ module Cloudinary::CarrierWave
|
|
46
45
|
end
|
47
46
|
options = args.extract_options!
|
48
47
|
options = self.transformation.merge(options) if self.version_name.present?
|
49
|
-
|
48
|
+
|
49
|
+
resource_type = Cloudinary::Utils.resource_type_for_format(self.format)
|
50
|
+
if self.class.storage_type == :authenticated
|
51
|
+
Cloudinary::Utils.signed_download_url(public_id, {:format=>self.format, :resource_type=>resource_type}.merge(options))
|
52
|
+
else
|
53
|
+
Cloudinary::Utils.cloudinary_url(public_id, {:format=>self.format, :resource_type=>resource_type, :type=>self.class.storage_type}.merge(options))
|
54
|
+
end
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
@@ -104,7 +109,7 @@ module Cloudinary::CarrierWave
|
|
104
109
|
end
|
105
110
|
|
106
111
|
class CloudinaryFile
|
107
|
-
attr_reader :identifier, :public_id, :filename, :format, :version
|
112
|
+
attr_reader :identifier, :public_id, :filename, :format, :version, :storage_type
|
108
113
|
def initialize(identifier, uploader)
|
109
114
|
@uploader = uploader
|
110
115
|
@identifier = identifier
|
@@ -115,12 +120,17 @@ module Cloudinary::CarrierWave
|
|
115
120
|
@filename = @identifier
|
116
121
|
@version = nil
|
117
122
|
end
|
123
|
+
@storage_type = uploader.class.storage_type
|
118
124
|
@public_id, @format = Cloudinary::CarrierWave.split_format(@filename)
|
119
125
|
end
|
120
126
|
|
121
127
|
def delete
|
122
128
|
Cloudinary::Uploader.destroy(self.public_id) if @uploader.delete_remote?
|
123
129
|
end
|
130
|
+
|
131
|
+
def exists?
|
132
|
+
Cloudinary::Uploader.exists?(self.identifier, :type=>self.storage_type)
|
133
|
+
end
|
124
134
|
end
|
125
135
|
|
126
136
|
def self.split_format(identifier)
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Cloudinary::CarrierWave
|
2
2
|
module ClassMethods
|
3
3
|
def make_private
|
4
|
-
|
5
|
-
process_all_versions :cloudinary_transformation=>{:type => :private}
|
4
|
+
self.storage_type = :private
|
6
5
|
end
|
7
6
|
|
8
7
|
def process_all_versions(*args)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class Cloudinary::CarrierWave::Storage < ::CarrierWave::Storage::Abstract
|
2
|
+
|
2
3
|
def store!(file)
|
3
4
|
return if !uploader.enable_processing
|
4
5
|
if uploader.is_main_uploader?
|
@@ -23,7 +24,9 @@ class Cloudinary::CarrierWave::Storage < ::CarrierWave::Storage::Abstract
|
|
23
24
|
params[:tags] = uploader.tags if uploader.tags
|
24
25
|
eager_versions = uploader.versions.values.select(&:eager)
|
25
26
|
params[:eager] = eager_versions.map{|version| [version.transformation, version.format]} if eager_versions.length > 0
|
26
|
-
|
27
|
+
params[:type]=uploader.class.storage_type
|
28
|
+
params[:resource_type] ||= :auto
|
29
|
+
|
27
30
|
uploader.metadata = Cloudinary::Uploader.upload(data, params)
|
28
31
|
if uploader.metadata["error"]
|
29
32
|
raise Cloudinary::CarrierWave::UploadError.new(uploader.metadata["error"]["message"], uploader.metadata["error"]["http_code"])
|
data/lib/cloudinary/uploader.rb
CHANGED
@@ -51,6 +51,15 @@ class Cloudinary::Uploader
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
def self.exists?(public_id, options={})
|
55
|
+
if options[:type] == :authenticated
|
56
|
+
cloudinary_url = Cloudinary::Utils.signed_download_url(public_id, options)
|
57
|
+
else
|
58
|
+
cloudinary_url = Cloudinary::Utils.cloudinary_url(public_id, options)
|
59
|
+
end
|
60
|
+
RestClient::Request.execute(:method => :head, :url => cloudinary_url, :timeout=>5).code.to_s =~ /2\d{2}/
|
61
|
+
end
|
62
|
+
|
54
63
|
def self.explicit(public_id, options={})
|
55
64
|
call_api("explicit", options) do
|
56
65
|
{
|
data/lib/cloudinary/utils.rb
CHANGED
@@ -112,6 +112,7 @@ class Cloudinary::Utils
|
|
112
112
|
return original_source # requested asset, but no metadata - probably local file. return.
|
113
113
|
end
|
114
114
|
end
|
115
|
+
|
115
116
|
type ||= :upload
|
116
117
|
|
117
118
|
if source.match(%r(^https?:/)i)
|
@@ -177,7 +178,7 @@ class Cloudinary::Utils
|
|
177
178
|
authenticated_distribution = options[:authenticated_distribution] || Cloudinary.config.authenticated_distribution || raise("Must supply authenticated_distribution")
|
178
179
|
@signers ||= Hash.new{|h,k| path, id = k; h[k] = AwsCfSigner.new(path, id)}
|
179
180
|
signer = @signers[[aws_private_key_path, aws_key_pair_id]]
|
180
|
-
url = Cloudinary::Utils.cloudinary_url(public_id, options.merge(:secure=>true, :secure_distribution=>authenticated_distribution, :private_cdn=>true))
|
181
|
+
url = Cloudinary::Utils.cloudinary_url(public_id, {:type=>:authenticated}.merge(options).merge(:secure=>true, :secure_distribution=>authenticated_distribution, :private_cdn=>true))
|
181
182
|
expires_at = options[:expires_at] || (Time.now+3600)
|
182
183
|
signer.sign(url, :ending => expires_at)
|
183
184
|
end
|
@@ -198,7 +199,8 @@ class Cloudinary::Utils
|
|
198
199
|
end
|
199
200
|
|
200
201
|
def self.random_public_id
|
201
|
-
|
202
|
+
sr = defined?(ActiveSupport::SecureRandom) ? ActiveSupport::SecureRandom : SecureRandom
|
203
|
+
sr.base64(20).downcase.gsub(/[^a-z0-9]/, "").sub(/^[0-9]+/, '')[0,20]
|
202
204
|
end
|
203
205
|
|
204
206
|
def self.signed_preloaded_image(result)
|
@@ -229,4 +231,14 @@ class Cloudinary::Utils
|
|
229
231
|
else [array]
|
230
232
|
end
|
231
233
|
end
|
234
|
+
|
235
|
+
IMAGE_FORMATS = %w(bmp png tif tiff jpg jpeg gif pdf ico)
|
236
|
+
|
237
|
+
def self.supported_image_format?(format)
|
238
|
+
IMAGE_FORMATS.include?(format.to_s.downcase)
|
239
|
+
end
|
240
|
+
|
241
|
+
def self.resource_type_for_format(format)
|
242
|
+
self.supported_image_format?(format) ? 'image' : 'raw'
|
243
|
+
end
|
232
244
|
end
|
data/lib/cloudinary/version.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.36
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-09-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rest-client
|