image_vise 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/image_vise.gemspec +3 -3
- data/lib/image_vise/render_engine.rb +19 -7
- data/lib/image_vise.rb +1 -1
- data/spec/image_vise/render_engine_spec.rb +6 -25
- 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: f8355426daabd653dd28ce986a379ce74d04015a
|
4
|
+
data.tar.gz: c986a6120fec633545eaaaddb57daf751fc3067f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ab6e3c250db5aa9870702b99b15c5bbbf29bc5d5acdd6647c8bdbb639a2b97b212cc6d9d5d3a10c9007a767ec8a53ede4625479415032d5ffe45e66be9efd21
|
7
|
+
data.tar.gz: b2db49f8c1655d6ff9064749098b856eb4616430e91644309c95fbe32d402e630c6eb224f430a79f9f9b46a4998d80f6f11737524b73cc8524c4aaaa777072f6
|
data/image_vise.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: image_vise 0.1.
|
5
|
+
# stub: image_vise 0.1.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "image_vise"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Julik Tarkhanov"]
|
14
|
-
s.date = "2016-
|
14
|
+
s.date = "2016-11-21"
|
15
15
|
s.description = "Image processing via URLs"
|
16
16
|
s.email = "me@julik.nl"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -6,10 +6,18 @@ class ImageVise::RenderEngine
|
|
6
6
|
'Allow' => "GET"
|
7
7
|
}.freeze
|
8
8
|
|
9
|
-
#
|
10
|
-
|
9
|
+
# Headers for error responses that denote an invalid or
|
10
|
+
# an unsatisfiable request
|
11
|
+
JSON_ERROR_HEADERS_REQUEST = DEFAULT_HEADERS.merge({
|
11
12
|
'Content-Type' => 'application/json',
|
12
|
-
'Cache-Control' => '
|
13
|
+
'Cache-Control' => 'public, max-age=600'
|
14
|
+
}).freeze
|
15
|
+
|
16
|
+
# Headers for error responses that denote
|
17
|
+
# an intermittent error (that permit retries)
|
18
|
+
JSON_ERROR_HEADERS_INTERMITTENT = DEFAULT_HEADERS.merge({
|
19
|
+
'Content-Type' => 'application/json',
|
20
|
+
'Cache-Control' => 'public, max-age=5'
|
13
21
|
}).freeze
|
14
22
|
|
15
23
|
# "public" of course. Add max-age so that there is _some_
|
@@ -25,7 +33,7 @@ class ImageVise::RenderEngine
|
|
25
33
|
RENDER_TIMEOUT_SECONDS = 10
|
26
34
|
|
27
35
|
# Which input files we permit (based on extensions stored in MagicBytes)
|
28
|
-
PERMITTED_SOURCE_FILE_EXTENSIONS = %w( gif png jpg )
|
36
|
+
PERMITTED_SOURCE_FILE_EXTENSIONS = %w( gif png jpg psd tif)
|
29
37
|
|
30
38
|
# Which output files are permitted (regardless of the input format
|
31
39
|
# the processed images will be converted to one of these types)
|
@@ -38,8 +46,12 @@ class ImageVise::RenderEngine
|
|
38
46
|
PNG_FILE_TYPE = MagicBytes::FileType.new('png','image/png').freeze
|
39
47
|
|
40
48
|
def bail(status, *errors_array)
|
41
|
-
|
42
|
-
|
49
|
+
headers = if (300...500).cover?(status)
|
50
|
+
JSON_ERROR_HEADERS_REQUEST.dup
|
51
|
+
else
|
52
|
+
JSON_ERROR_HEADERS_INTERMITTENT.dup
|
53
|
+
end
|
54
|
+
response = [status.to_i, headers, [JSON.pretty_generate({errors: errors_array})]]
|
43
55
|
throw :__bail, response
|
44
56
|
end
|
45
57
|
|
@@ -74,7 +86,7 @@ class ImageVise::RenderEngine
|
|
74
86
|
image_rack_response(render_destination_file, render_file_type, etag)
|
75
87
|
rescue *permanent_failures => e
|
76
88
|
handle_request_error(e)
|
77
|
-
http_status_code = e.respond_to?(:http_status) ? e.http_status :
|
89
|
+
http_status_code = e.respond_to?(:http_status) ? e.http_status : 400
|
78
90
|
raise_exception_or_error_response(e, http_status_code)
|
79
91
|
rescue Exception => e
|
80
92
|
if http_status_code = (e.respond_to?(:http_status) && e.http_status)
|
data/lib/image_vise.rb
CHANGED
@@ -39,7 +39,7 @@ describe ImageVise::RenderEngine do
|
|
39
39
|
ImageVise.reset_secret_keys!
|
40
40
|
end
|
41
41
|
|
42
|
-
it 'halts with
|
42
|
+
it 'halts with 400 when the requested image cannot be opened by ImageMagick' do
|
43
43
|
uri = Addressable::URI.parse(public_url)
|
44
44
|
ImageVise.add_allowed_host!(uri.host)
|
45
45
|
ImageVise.add_secret_key!('l33tness')
|
@@ -55,12 +55,12 @@ describe ImageVise::RenderEngine do
|
|
55
55
|
expect(app).to receive(:handle_request_error).and_call_original
|
56
56
|
|
57
57
|
get image_request.to_path_params('l33tness')
|
58
|
-
expect(last_response.status).to eq(
|
59
|
-
expect(last_response['Cache-Control']).to
|
58
|
+
expect(last_response.status).to eq(400)
|
59
|
+
expect(last_response['Cache-Control']).to match(/public/)
|
60
60
|
expect(last_response.body).to include('Unsupported/unknown')
|
61
61
|
end
|
62
62
|
|
63
|
-
it 'halts with
|
63
|
+
it 'halts with 400 when a file:// URL is given and filesystem access is not enabled' do
|
64
64
|
uri = 'file://' + test_image_path
|
65
65
|
ImageVise.deny_filesystem_sources!
|
66
66
|
ImageVise.add_secret_key!('l33tness')
|
@@ -105,7 +105,7 @@ describe ImageVise::RenderEngine do
|
|
105
105
|
|
106
106
|
expect(last_response.status).to eq(error_code)
|
107
107
|
expect(last_response.headers).to have_key('Cache-Control')
|
108
|
-
expect(last_response.headers['Cache-Control']).to
|
108
|
+
expect(last_response.headers['Cache-Control']).to match(/public/)
|
109
109
|
|
110
110
|
expect(last_response.headers['Content-Type']).to eq('application/json')
|
111
111
|
parsed = JSON.load(last_response.body)
|
@@ -254,7 +254,7 @@ describe ImageVise::RenderEngine do
|
|
254
254
|
examine_image_from_string(last_response.body)
|
255
255
|
end
|
256
256
|
|
257
|
-
it '
|
257
|
+
it 'permits a PSD file by default' do
|
258
258
|
uri = Addressable::URI.parse(public_url_psd)
|
259
259
|
ImageVise.add_allowed_host!(uri.host)
|
260
260
|
ImageVise.add_secret_key!('l33tness')
|
@@ -262,26 +262,8 @@ describe ImageVise::RenderEngine do
|
|
262
262
|
p = ImageVise::Pipeline.new.geom(geometry_string: '220x220').ellipse_stencil
|
263
263
|
image_request = ImageVise::ImageRequest.new(src_url: uri.to_s, pipeline: p)
|
264
264
|
|
265
|
-
get image_request.to_path_params('l33tness')
|
266
|
-
expect(last_response.status).to eq(422)
|
267
|
-
expect(last_response.body).to include('unknown input file format .psd')
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'permits a PSD file if it is permitted via a method override' do
|
271
|
-
uri = Addressable::URI.parse(public_url_psd)
|
272
|
-
ImageVise.add_allowed_host!(uri.host)
|
273
|
-
ImageVise.add_secret_key!('l33tness')
|
274
|
-
|
275
|
-
p = ImageVise::Pipeline.new.geom(geometry_string: '220x220')
|
276
|
-
image_request = ImageVise::ImageRequest.new(src_url: uri.to_s, pipeline: p)
|
277
|
-
|
278
|
-
class << app
|
279
|
-
def source_file_type_permitted?(type); true; end
|
280
|
-
end
|
281
|
-
|
282
265
|
get image_request.to_path_params('l33tness')
|
283
266
|
expect(last_response.status).to eq(200)
|
284
|
-
expect(last_response.headers['Content-Type']).to eq('image/png')
|
285
267
|
end
|
286
268
|
|
287
269
|
it 'destroys all the loaded PSD layers' do
|
@@ -293,7 +275,6 @@ describe ImageVise::RenderEngine do
|
|
293
275
|
image_request = ImageVise::ImageRequest.new(src_url: uri.to_s, pipeline: p)
|
294
276
|
|
295
277
|
class << app
|
296
|
-
def source_file_type_permitted?(type); true; end
|
297
278
|
def raise_exceptions?; true; end
|
298
279
|
end
|
299
280
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_vise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julik Tarkhanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: patron
|