Skip to content

Commit

Permalink
quick fix for thumbnail logic (#878)
Browse files Browse the repository at this point in the history
updates thumbnail indexing logic to ensure that:
- a fully formed IIIF url (with parameters) is passed as is, without spurious parameters added
- if the IIIF resource is improperly formatted, we don't index it (Ursus will use the default icon)
  • Loading branch information
sourcefilter authored May 27, 2021
1 parent 5816ef6 commit 4db4fd0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
7 changes: 4 additions & 3 deletions app/indexers/collection_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ def solr_during_indexing

def thumbnail_url
thumbnail = object.thumbnail_link || thumbnail_from_access_copy
if thumbnail.to_s.include?('/iiif/2/')
"#{thumbnail}/full/!200,200/0/default.jpg"
elsif ['.svg', '.png', '.jpg'].include? File.extname(thumbnail.to_s)
case thumbnail
when /\.(svg)|(png)|(jpg)$/
thumbnail
when /\/iiif\/2\/[^\/]+$/
"#{thumbnail}/full/!200,200/0/default.jpg"
else
return nil
end
Expand Down
7 changes: 4 additions & 3 deletions app/indexers/work_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ def human_readable_rights_statement

def thumbnail_url
thumbnail = object.thumbnail_link || thumbnail_from_access_copy
if thumbnail.to_s.include?('/iiif/2/')
"#{thumbnail}/full/!200,200/0/default.jpg"
elsif ['.svg', '.png', '.jpg'].include? File.extname(thumbnail.to_s)
case thumbnail
when /\.(svg)|(png)|(jpg)$/
thumbnail
when /\/iiif\/2\/[^\/]+$/
"#{thumbnail}/full/!200,200/0/default.jpg"
else
return nil
end
Expand Down
16 changes: 16 additions & 0 deletions spec/indexers/collection_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@
it 'adds iiif parameters' do
expect(solr_document['thumbnail_url_ss']).to eq 'https://fake.url/iiif/2/id/full/!200,200/0/default.jpg'
end

context 'when it already includes iiif parameters' do
let(:thumbnail_link) { 'https://fake.url/iiif/2/id/full/!200,200/0/default.jpg' }

it 'does not add them again' do
expect(solr_document['thumbnail_url_ss']).to eq 'https://fake.url/iiif/2/id/full/!200,200/0/default.jpg'
end
end

context 'when it doesn\'t match the expected format' do
let(:thumbnail_link) { 'https://fake.url/iiif/2/id/full/!200,200/' }

it 'returns nil' do
expect(solr_document['thumbnail_url_ss']).to eq nil
end
end
end

context 'when thumbnail_link is an image url' do
Expand Down
16 changes: 16 additions & 0 deletions spec/indexers/work_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,22 @@
it 'adds iiif parameters' do
expect(solr_document['thumbnail_url_ss']).to eq 'https://fake.url/iiif/2/id/full/!200,200/0/default.jpg'
end

context 'when it already includes iiif parameters' do
let(:thumbnail_link) { 'https://fake.url/iiif/2/id/full/!200,200/0/default.jpg' }

it 'does not add them again' do
expect(solr_document['thumbnail_url_ss']).to eq 'https://fake.url/iiif/2/id/full/!200,200/0/default.jpg'
end
end

context 'when it doesn\'t match the expected format' do
let(:thumbnail_link) { 'https://fake.url/iiif/2/id/full/!200,200/' }

it 'returns nil' do
expect(solr_document['thumbnail_url_ss']).to eq nil
end
end
end

context 'when thumbnail_link is an image url' do
Expand Down

0 comments on commit 4db4fd0

Please sign in to comment.