Skip to content

Commit

Permalink
Merge pull request #1142 from sul-dlss/fix-iiif-version
Browse files Browse the repository at this point in the history
Check that version is ready before generating iiif manifest
  • Loading branch information
lwrubel authored Aug 19, 2024
2 parents 89540fd + db462ee commit bbee897
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/controllers/iiif_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class IiifController < ApplicationController
before_action :load_purl
before_action :load_version

def manifest
iiif_version = params[:iiif_version] == 'v3' ? 3 : 2
@version = @purl.version(:head)

return unless stale?(last_modified: @version.updated_at.utc, etag: "#{@version.cache_key}/#{iiif_version}/#{@version.updated_at.utc}")

# Avoid trying to create a manifest for geo objects, because we don't yet have a way of knowing which file is a primary.
Expand Down Expand Up @@ -88,4 +89,9 @@ def iiif_manifest
def load_purl
@purl = PurlResource.find(params[:purl_id] || params[:id])
end

def load_version
@version = @purl.version(:head)
raise PurlVersion::ObjectNotReady, params[:id] unless @version.ready?
end
end
9 changes: 8 additions & 1 deletion spec/requests/iiif3_manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
expect(json['metadata']).to eq(expected_dc_metadata)
end

context 'when purl does not exist (dark)' do
it 'is not found' do
get '/bc123df4567/iiif3/manifest'
expect(response).to have_http_status(:not_found)
end
end

context 'when viewing direction is defined' do
it 'includes viewing direction' do
get '/yr183sf1341/iiif3/manifest'
Expand Down Expand Up @@ -308,7 +315,7 @@
context 'when the object has no published files' do
let(:druid) { 'bg387kw8222' }
let(:resource) { instance_double(PurlResource, version:) }
let(:version) { instance_double(PurlVersion, type: 'image', updated_at: 2.days.ago, cache_key: 'resource/xxx') }
let(:version) { instance_double(PurlVersion, type: 'image', updated_at: 2.days.ago, cache_key: 'resource/xxx', ready?: true) }

before do
allow(PurlResource).to receive(:find).and_return(resource)
Expand Down

0 comments on commit bbee897

Please sign in to comment.