image_server 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/image_server/active_record.rb +12 -7
- data/lib/image_server/adapters/http.rb +6 -4
- data/lib/image_server/installer.rb +1 -1
- data/lib/image_server/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9147befb6357ed6c9e3b160794ebc46b535a4ee2
|
4
|
+
data.tar.gz: 8be91bbfa024ee310ce5286129b9c07275491eb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f13101ae69fc6dbc1c2d80cc608d37ef38d79f901b0cce96fdb2bcd2f86f415585df3c094d75f68d08c38b747594c4d288117e0aadf1ed0b0961c99b87bbbb95
|
7
|
+
data.tar.gz: 62d26cd64e71734efa59f17201e2fc9ff55439c8ef8be5871e3b66a5616c235f3b0b35ed7bd087f5324c7f213dc8b7f24577bfe8cc967af9d4ceb69b3c683cb5
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module ImageServer
|
2
2
|
module ActiveRecord
|
3
|
-
def image_server(column, namespace: 'img', versions: nil, processing_formats: [:jpg], default_size: 'full_size', default_format: 'jpg', sharded_cdn_template: nil)
|
4
|
-
sizes = versions.values.sort.uniq
|
3
|
+
def image_server(column, namespace: 'img', versions: nil, processing: nil, processing_formats: [:jpg], default_size: 'full_size', default_format: 'jpg', sharded_cdn_template: nil)
|
5
4
|
keys = versions.keys.sort.uniq
|
6
5
|
processing_formats = processing_formats.map(&:to_s).sort.uniq
|
7
|
-
|
6
|
+
processing_versions = processing[:versions].sort.uniq if processing
|
7
|
+
processing_versions ||= versions.values.sort.uniq
|
8
|
+
outputs = processing_versions.flat_map { |s| processing_formats.map { |f| "#{s}.#{f}" } }
|
8
9
|
outputs_str = outputs.join(',')
|
9
|
-
|
10
10
|
namespace_constant = "#{column.to_s.upcase}_NAMESPACE"
|
11
11
|
outputs_constant = "#{column.to_s.upcase}_OUTPUTS_STR"
|
12
|
+
processing_versions_constant = "#{column.to_s.upcase}_PROCESSING_VERSIONS"
|
12
13
|
keys_constant = "#{column.to_s.upcase}_KEYS"
|
13
14
|
|
14
15
|
sharded_cdn_template_constant = "#{column.to_s.upcase}_SHARDED_CDN_TEMPLATE"
|
@@ -18,6 +19,7 @@ module ImageServer
|
|
18
19
|
#{namespace_constant} = '#{namespace}'
|
19
20
|
#{outputs_constant} = '#{outputs_str}'
|
20
21
|
#{keys_constant} = #{keys}
|
22
|
+
#{processing_versions_constant} = #{processing_versions}
|
21
23
|
#{sharded_cdn_template_constant} = #{sharded_cdn_template}
|
22
24
|
|
23
25
|
def remote_#{column}_url=(url)
|
@@ -27,12 +29,11 @@ module ImageServer
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def #{column}(options={})
|
30
|
-
processing = #{column}_hash.blank?
|
31
32
|
default_options = { protocol: #{column}_cdn_protocol,
|
32
33
|
domain: #{column}_cdn_domain,
|
33
34
|
default_size: '#{default_size}',
|
34
35
|
format: '#{default_format}',
|
35
|
-
processing:
|
36
|
+
processing: #{column}_processing?,
|
36
37
|
object: self }
|
37
38
|
ImageServer::Image.new(#{namespace_constant}, #{column}_hash, default_options.merge(options))
|
38
39
|
end
|
@@ -48,12 +49,16 @@ module ImageServer
|
|
48
49
|
|
49
50
|
private
|
50
51
|
|
52
|
+
def #{column}_processing?
|
53
|
+
#{column}_hash == nil || #{column}_hash == ''
|
54
|
+
end
|
55
|
+
|
51
56
|
def #{column}_cdn_protocol
|
52
57
|
ImageServer.configuration.cdn_protocol
|
53
58
|
end
|
54
59
|
|
55
60
|
def #{column}_cdn_domain
|
56
|
-
return #{column}_host if #{column}
|
61
|
+
return #{column}_host if #{column}_processing?
|
57
62
|
return #{column}_host unless #{sharded_cdn_template_constant}
|
58
63
|
shard = #{column}_hash[0].hex % #{column}_sharded_host_count
|
59
64
|
#{sharded_cdn_template_constant} % shard
|
@@ -18,9 +18,10 @@ module ImageServer
|
|
18
18
|
logger.info "ImageServer::Adapters::Http --> uploading to image server: [#{upload_uri}]"
|
19
19
|
|
20
20
|
response = Net::HTTP.start(upload_uri.host, upload_uri.port) do |http|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
request = Net::HTTP::Post.new(upload_uri.request_uri)
|
22
|
+
request['Accept'] = "application/json"
|
23
|
+
request['Content-Type'] = "application/json"
|
24
|
+
request.body = if source_is_url?
|
24
25
|
'{}' # blank body
|
25
26
|
elsif @source.is_a?(File)
|
26
27
|
@source
|
@@ -30,7 +31,8 @@ module ImageServer
|
|
30
31
|
raise('Not supported')
|
31
32
|
end
|
32
33
|
|
33
|
-
http.
|
34
|
+
http.read_timeout = 60
|
35
|
+
http.request(request)
|
34
36
|
end
|
35
37
|
|
36
38
|
ErrorHandler.new(response).handle_errors!
|
data/lib/image_server/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Millan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|