cloudinary 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cloudinary/static.rb +19 -2
- data/lib/cloudinary/uploader.rb +2 -2
- data/lib/cloudinary/utils.rb +21 -18
- data/lib/cloudinary/version.rb +1 -1
- metadata +2 -2
data/lib/cloudinary/static.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'find'
|
2
2
|
class Cloudinary::Static
|
3
|
-
IGNORE_FILES = [".svn", "CVS", "RCS", ".git", ".hg"
|
3
|
+
IGNORE_FILES = [".svn", "CVS", "RCS", ".git", ".hg"]
|
4
|
+
SUPPORTED_IMAGES = [/\.gif$/i, /\.jpe?g$/i, /\.png$/i, /\.bmp$/i, /\.ico$/i]
|
4
5
|
STATIC_IMAGE_DIRS = ["app/assets/images", "public/images"]
|
5
6
|
METADATA_FILE = ".cloudinary.static"
|
6
7
|
METADATA_TRASH_FILE = ".cloudinary.static.trash"
|
@@ -14,11 +15,13 @@ class Cloudinary::Static
|
|
14
15
|
dir.find do
|
15
16
|
|path|
|
16
17
|
file = path.basename.to_s
|
17
|
-
if
|
18
|
+
if ignore_files.any?{|pattern| pattern.is_a?(String) ? pattern == file : file.match(pattern)}
|
18
19
|
Find.prune
|
19
20
|
next
|
20
21
|
elsif path.directory?
|
21
22
|
next
|
23
|
+
elsif SUPPORTED_IMAGES.none?{|pattern| pattern.is_a?(String) ? pattern == file : file.match(pattern)}
|
24
|
+
next
|
22
25
|
else
|
23
26
|
relative_path = path.relative_path_from(Rails.root)
|
24
27
|
public_path = path.relative_path_from(dir.dirname)
|
@@ -65,6 +68,7 @@ class Cloudinary::Static
|
|
65
68
|
found_paths = Set.new
|
66
69
|
found_public_ids = Set.new
|
67
70
|
metadata_lines = []
|
71
|
+
counts = { :not_changed => 0, :uploaded => 0, :deleted => 0, :not_found => 0}
|
68
72
|
self.discover do
|
69
73
|
|path, public_path|
|
70
74
|
next if found_paths.include?(path)
|
@@ -77,8 +81,12 @@ class Cloudinary::Static
|
|
77
81
|
found_public_ids << public_id
|
78
82
|
current_metadata = metadata.delete(public_path.to_s)
|
79
83
|
if current_metadata && current_metadata["public_id"] == public_id # Signature match
|
84
|
+
counts[:not_changed] += 1
|
85
|
+
$stderr.print "#{public_path} - #{public_id} - Not changed\n"
|
80
86
|
result = current_metadata
|
81
87
|
else
|
88
|
+
counts[:uploaded] += 1
|
89
|
+
$stderr.print "#{public_path} - #{public_id} - Uploading\n"
|
82
90
|
result = Cloudinary::Uploader.upload(Cloudinary::Blob.new(data, :original_filename=>path.to_s),
|
83
91
|
options.merge(:format=>format, :public_id=>public_id, :type=>:asset)
|
84
92
|
)
|
@@ -86,12 +94,18 @@ class Cloudinary::Static
|
|
86
94
|
metadata_lines << [public_path, public_id, Time.now.to_i, result["version"], result["width"], result["height"]].join("\t")+"\n"
|
87
95
|
end
|
88
96
|
File.open(self.metadata_file_path, "w"){|f| f.print(metadata_lines.join)}
|
97
|
+
metadata.to_a.each do |path, info|
|
98
|
+
counts[:not_found] += 1
|
99
|
+
$stderr.print "#{path} - #{info["public_id"]} - Not found\n"
|
100
|
+
end
|
89
101
|
# Files no longer needed
|
90
102
|
trash = metadata.to_a + self.metadata(metadata_trash_file_path, false).reject{|public_path, info| found_public_ids.include?(info["public_id"])}
|
91
103
|
|
92
104
|
if delete_missing
|
93
105
|
trash.each do
|
94
106
|
|path, info|
|
107
|
+
counts[:deleted] += 1
|
108
|
+
$stderr.print "#{path} - #{info["public_id"]} - Deleting\n"
|
95
109
|
Cloudinary::Uploader.destroy(info["public_id"], options.merge(:type=>:asset))
|
96
110
|
end
|
97
111
|
FileUtils.rm_f(self.metadata_trash_file_path)
|
@@ -103,5 +117,8 @@ class Cloudinary::Static
|
|
103
117
|
end
|
104
118
|
File.open(self.metadata_trash_file_path, "w"){|f| f.print(metadata_lines.join)}
|
105
119
|
end
|
120
|
+
|
121
|
+
$stderr.print "\nCompleted syncing static resources to Cloudinary\n"
|
122
|
+
$stderr.print counts.sort.reject{|k,v| v == 0}.map{|k,v| "#{v} #{k.to_s.gsub('_', ' ').capitalize}"}.join(", ") + "\n"
|
106
123
|
end
|
107
124
|
end
|
data/lib/cloudinary/uploader.rb
CHANGED
@@ -12,7 +12,7 @@ class Cloudinary::Uploader
|
|
12
12
|
:callback=> options[:callback],
|
13
13
|
:format=>options[:format],
|
14
14
|
:type=>options[:type],
|
15
|
-
:tags=>options[:tags] && Cloudinary::Utils.build_array(options[:tags]).join(",")}
|
15
|
+
:tags=>options[:tags] && Cloudinary::Utils.build_array(options[:tags]).join(",")}
|
16
16
|
if options[:eager]
|
17
17
|
params[:eager] = options[:eager].map do
|
18
18
|
|transformation, format|
|
@@ -104,7 +104,7 @@ class Cloudinary::Uploader
|
|
104
104
|
resource_type = options.delete(:resource_type) || "image"
|
105
105
|
result = nil
|
106
106
|
cloud_name = Cloudinary.config.cloud_name || raise("Must supply cloud_name")
|
107
|
-
RestClient::Request.execute(:method => :post, :url => "#{cloudinary}/v1_1/#{cloud_name}/#{resource_type}/#{action}", :payload => params, :timeout=>60) do
|
107
|
+
RestClient::Request.execute(:method => :post, :url => "#{cloudinary}/v1_1/#{cloud_name}/#{resource_type}/#{action}", :payload => params.reject{|k, v| v.blank?}, :timeout=>60) do
|
108
108
|
|response, request, tmpresult|
|
109
109
|
raise "Server returned unexpected status code - #{response.code} - #{response.body}" if ![200,400,500].include?(response.code)
|
110
110
|
begin
|
data/lib/cloudinary/utils.rb
CHANGED
@@ -50,26 +50,29 @@ class Cloudinary::Utils
|
|
50
50
|
secure = options.delete(:secure) || Cloudinary.config.secure
|
51
51
|
private_cdn = options.delete(:private_cdn) || Cloudinary.config.private_cdn
|
52
52
|
secure_distribution = options.delete(:secure_distribution) || Cloudinary.config.secure_distribution
|
53
|
-
|
54
|
-
|
55
|
-
if
|
56
|
-
if source.
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
force_remote = options.delete(:force_remote)
|
54
|
+
|
55
|
+
if !force_remote
|
56
|
+
return source if (type.nil? || type == :asset) && source.match(%r(^https?:/)i)
|
57
|
+
if source.start_with?("/")
|
58
|
+
if source.start_with?("/images/")
|
59
|
+
source = source.sub(%r(/images/), '')
|
60
|
+
else
|
61
|
+
return source
|
62
|
+
end
|
63
|
+
end
|
64
|
+
@metadata ||= Cloudinary::Static.metadata
|
65
|
+
if @metadata["images/#{source}"]
|
66
|
+
return source if !Cloudinary.config.static_image_support
|
67
|
+
type = :asset
|
68
|
+
original_source = source
|
69
|
+
source = @metadata["images/#{source}"]["public_id"]
|
70
|
+
source += File.extname(original_source) if !format
|
71
|
+
elsif type == :asset
|
72
|
+
return source # requested asset, but no metadata - probably local file. return.
|
60
73
|
end
|
61
|
-
end
|
62
|
-
type ||= :upload
|
63
|
-
@metadata ||= Cloudinary::Static.metadata
|
64
|
-
if @metadata["images/#{source}"]
|
65
|
-
return source if !Cloudinary.config.static_image_support
|
66
|
-
type = :asset
|
67
|
-
original_source = source
|
68
|
-
source = @metadata["images/#{source}"]["public_id"]
|
69
|
-
source += File.extname(original_source) if !format
|
70
|
-
elsif type == :asset
|
71
|
-
return source # requested asset, but no metadata - probably local file. return.
|
72
74
|
end
|
75
|
+
type ||= :upload
|
73
76
|
|
74
77
|
if cloud_name.start_with?("/")
|
75
78
|
prefix = "/res" + cloud_name
|
data/lib/cloudinary/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cloudinary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nadav Soferman
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2012-04-
|
15
|
+
date: 2012-04-04 00:00:00 +03:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|