riiif 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/riiif/images_controller.rb +3 -1
- data/app/models/riiif/image_information.rb +28 -0
- data/lib/riiif/version.rb +1 -1
- data/lib/riiif.rb +2 -2
- data/spec/controllers/riiif/images_controller_spec.rb +41 -18
- data/spec/models/riiif/image_information_spec.rb +19 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a89139fdccd2b6824042ae7bdae9880eb28d334
|
4
|
+
data.tar.gz: 7b13b9280123669a73aa533a50f218f9daccdb53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3174488a09bcb1ecad59db2a8d7e338ab863af1d2a5afe07bbd746fd161ced2a0cf4bfc4ac85c9d4067fd41d089525e8419c0bc489be8f1cd8755e7718dfeed
|
7
|
+
data.tar.gz: 6afbc6db3a6029f38c35f46c204402c84de393ea1327fd3455e4ae0e798856e8c8726e9ad8e8e8526c5846392880d35c1ba60f45badb5a6c76d6942ef8cea323
|
@@ -33,10 +33,12 @@ module Riiif
|
|
33
33
|
def info
|
34
34
|
image = model.new(image_id)
|
35
35
|
if authorization_service.can?(:info, image)
|
36
|
+
image_info = image.info
|
37
|
+
return render json: { error: 'no info' }, status: :not_found unless image_info.valid?
|
36
38
|
headers['Access-Control-Allow-Origin'] = '*'
|
37
39
|
# Set a Cache-Control header
|
38
40
|
expires_in cache_expires, public: public_cache?
|
39
|
-
render json:
|
41
|
+
render json: image_info.to_h.merge(server_info), content_type: 'application/ld+json'
|
40
42
|
else
|
41
43
|
render json: { error: 'unauthorized' }, status: :unauthorized
|
42
44
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Riiif
|
2
|
+
# This is the result of calling the Riiif.image_info service. It stores the height & width
|
3
|
+
class ImageInformation
|
4
|
+
def initialize(width, height)
|
5
|
+
@width = width
|
6
|
+
@height = height
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :width, :height
|
10
|
+
|
11
|
+
def to_h
|
12
|
+
{ width: width, height: height }
|
13
|
+
end
|
14
|
+
|
15
|
+
# Image information is only valid if height and width are present.
|
16
|
+
# If an image info service doesn't have the value yet (not characterized perhaps?)
|
17
|
+
# then we wouldn't want to cache this value.
|
18
|
+
def valid?
|
19
|
+
width.present? && height.present?
|
20
|
+
end
|
21
|
+
|
22
|
+
def ==(other)
|
23
|
+
other.class == self.class &&
|
24
|
+
other.width == width &&
|
25
|
+
other.height == height
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/riiif/version.rb
CHANGED
data/lib/riiif.rb
CHANGED
@@ -13,11 +13,11 @@ module Riiif
|
|
13
13
|
class Error < RuntimeError; end
|
14
14
|
class InvalidAttributeError < Error; end
|
15
15
|
class ImageNotFoundError < Error; end
|
16
|
+
|
16
17
|
# This error is raised when Riiif can't convert an image
|
17
18
|
class ConversionError < Error; end
|
18
19
|
|
19
20
|
Transformation = Struct.new(:crop, :size, :quality, :rotation, :format)
|
20
|
-
ImageInformation = Struct.new(:width, :height)
|
21
21
|
mattr_accessor :not_found_image # the image to use when a lookup fails
|
22
|
-
mattr_accessor :unauthorized_image # the image to use when a
|
22
|
+
mattr_accessor :unauthorized_image # the image to use when a user doesn't have access
|
23
23
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'open-uri'
|
3
3
|
|
4
|
-
describe Riiif::ImagesController do
|
4
|
+
RSpec.describe Riiif::ImagesController do
|
5
5
|
let(:filename) { File.expand_path('spec/samples/world.jp2') }
|
6
6
|
routes { Riiif::Engine.routes }
|
7
7
|
|
@@ -19,6 +19,7 @@ describe Riiif::ImagesController do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
22
23
|
describe '#show' do
|
23
24
|
it 'sends images to the service' do
|
24
25
|
image = double
|
@@ -131,23 +132,45 @@ describe Riiif::ImagesController do
|
|
131
132
|
end
|
132
133
|
|
133
134
|
describe 'info' do
|
134
|
-
|
135
|
-
image
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
135
|
+
context 'the happy path' do
|
136
|
+
let(:image) { double }
|
137
|
+
let(:json) { JSON.parse(response.body) }
|
138
|
+
|
139
|
+
before do
|
140
|
+
allow(Riiif::Image).to receive(:new).with('abcd1234').and_return(image)
|
141
|
+
allow(image).to receive(:info).and_return(Riiif::ImageInformation.new(6000, 4000))
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'returns info' do
|
145
|
+
get :info, params: { id: 'abcd1234', format: 'json' }
|
146
|
+
expect(response).to be_successful
|
147
|
+
expect(json).to eq '@context' => 'http://iiif.io/api/image/2/context.json',
|
148
|
+
'@id' => 'http://test.host/abcd1234',
|
149
|
+
'width' => 6000,
|
150
|
+
'height' => 4000,
|
151
|
+
'profile' => ['http://iiif.io/api/image/2/level1.json', 'formats' => %w(jpg png)],
|
152
|
+
'protocol' => 'http://iiif.io/api/image'
|
153
|
+
expect(response.headers['Link']).to eq '<http://iiif.io/api/image/2/level1.json>;rel="profile"'
|
154
|
+
expect(response.headers['Content-Type']).to eq 'application/ld+json; charset=utf-8'
|
155
|
+
expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
|
156
|
+
expect(response.headers['Cache-Control']).to eq "max-age=#{1.year.to_i}, private"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'when the info_service has an invalid result' do
|
161
|
+
let(:image) { double }
|
162
|
+
let(:json) { JSON.parse(response.body) }
|
163
|
+
|
164
|
+
before do
|
165
|
+
allow(Riiif::Image).to receive(:new).with('abcd1234').and_return(image)
|
166
|
+
allow(image).to receive(:info).and_return(Riiif::ImageInformation.new(nil, nil))
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'returns an error' do
|
170
|
+
get :info, params: { id: 'abcd1234', format: 'json' }
|
171
|
+
expect(response).to be_not_found
|
172
|
+
expect(json).to eq 'error' => 'no info'
|
173
|
+
end
|
151
174
|
end
|
152
175
|
|
153
176
|
context 'with an unauthorized image' do
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Riiif::ImageInformation do
|
4
|
+
describe '#valid?' do
|
5
|
+
subject { info.valid? }
|
6
|
+
|
7
|
+
context 'with valid dimensions' do
|
8
|
+
let(:info) { described_class.new(100, 200) }
|
9
|
+
|
10
|
+
it { is_expected.to be true }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with nil dimensions' do
|
14
|
+
let(:info) { described_class.new(nil, nil) }
|
15
|
+
|
16
|
+
it { is_expected.to be false }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riiif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- app/controllers/riiif/images_controller.rb
|
149
149
|
- app/models/riiif/file.rb
|
150
150
|
- app/models/riiif/image.rb
|
151
|
+
- app/models/riiif/image_information.rb
|
151
152
|
- app/services/riiif/command_runner.rb
|
152
153
|
- app/services/riiif/image_magick_info_extractor.rb
|
153
154
|
- app/services/riiif/imagemagick_command_factory.rb
|
@@ -177,6 +178,7 @@ files:
|
|
177
178
|
- spec/models/riiif/akubra_system_file_resolver_spec.rb
|
178
179
|
- spec/models/riiif/file_system_file_resolver_spec.rb
|
179
180
|
- spec/models/riiif/http_file_resolver_spec.rb
|
181
|
+
- spec/models/riiif/image_information_spec.rb
|
180
182
|
- spec/models/riiif/image_spec.rb
|
181
183
|
- spec/routing/redirect_spec.rb
|
182
184
|
- spec/routing/resize_routes_spec.rb
|
@@ -204,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
206
|
version: '0'
|
205
207
|
requirements: []
|
206
208
|
rubyforge_project:
|
207
|
-
rubygems_version: 2.
|
209
|
+
rubygems_version: 2.6.12
|
208
210
|
signing_key:
|
209
211
|
specification_version: 4
|
210
212
|
summary: A rails engine that support IIIF requests
|
@@ -213,6 +215,7 @@ test_files:
|
|
213
215
|
- spec/models/riiif/akubra_system_file_resolver_spec.rb
|
214
216
|
- spec/models/riiif/file_system_file_resolver_spec.rb
|
215
217
|
- spec/models/riiif/http_file_resolver_spec.rb
|
218
|
+
- spec/models/riiif/image_information_spec.rb
|
216
219
|
- spec/models/riiif/image_spec.rb
|
217
220
|
- spec/routing/redirect_spec.rb
|
218
221
|
- spec/routing/resize_routes_spec.rb
|