diff --git a/app/models/cocina.rb b/app/models/cocina.rb index b8bf1902..bc6d12d0 100644 --- a/app/models/cocina.rb +++ b/app/models/cocina.rb @@ -25,7 +25,7 @@ def self.metadata_cache_key(druid, version) end def self.public_json_url(druid, version) - return "#{Settings.purl.url}#{druid}/#{version}.json" unless version == :head + return "#{Settings.purl.url}#{druid}/version/#{version}.json" unless version == :head "#{Settings.purl.url}#{druid}.json" end diff --git a/config/routes.rb b/config/routes.rb index 7a2f2085..9f14636b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,15 +2,13 @@ druid_regex = /([a-z]{2})(\d{3})([a-z]{2})(\d{4})/i get '/object/:id' => 'object#show', as: :object - get '/object/:id/:version_id', to: 'object#show', constraints: { version_id: /v\d+/ } + get '/object/:id/version/:version_id', to: 'object#show' constraints id: druid_regex do scope format: false do # Tell rails not to separate out the filename suffixes scope '/v2' do # versionable files - constraints version_id: /v\d+/ do - get '/file/:id/:version_id/*file_name', to: 'file#show', as: :versioned_file - options '/file/:id/:version_id/*file_name', to: 'file#options' - end + get '/file/:id/version/:version_id/*file_name', to: 'file#show', as: :versioned_file + options '/file/:id/version/:version_id/*file_name', to: 'file#options' end # File/auth routes without druid namespace @@ -68,7 +66,7 @@ match '/image/iiif/:identifier/info.json' => 'iiif#metadata_options', via: [:options] end - # As of Sept 2017, the legacy service was still used by Revs and Bassi Verati/FRDA + # As of Aug 2024, the legacy service was still used by Bassi Verati/FRDA # It's also likely used by other applications too. # The LegacyImageService is just a facade that redirects to the appropriate IIIF URI constraints id: druid_regex, file_name: %r{[^/]+}, format: %r{(jpg|png|gif|jp2)}, size: %r{(#{Settings.legacy.sizes.join('|')})} do diff --git a/spec/models/cocina_spec.rb b/spec/models/cocina_spec.rb index f59dbfd9..af3daf97 100644 --- a/spec/models/cocina_spec.rb +++ b/spec/models/cocina_spec.rb @@ -59,12 +59,12 @@ context 'when requesting a specific version' do before do - stub_request(:get, "https://purl.stanford.edu/abc/v2.json") + stub_request(:get, "https://purl.stanford.edu/abc/version/2.json") .to_return(status: 200, body: json) end it 'gets all the files for a resource' do - actual = described_class.find('abc', 'v2').files.map { |file| "#{file.id}/#{file.file_name}" } + actual = described_class.find('abc', '2').files.map { |file| "#{file.id}/#{file.file_name}" } expect(actual).to contain_exactly('abc/26855.jp2', 'abc/123.jp2') end diff --git a/spec/requests/versioned_file_spec.rb b/spec/requests/versioned_file_spec.rb index 9c7d38c8..ff30f4cd 100644 --- a/spec/requests/versioned_file_spec.rb +++ b/spec/requests/versioned_file_spec.rb @@ -8,7 +8,7 @@ end let(:druid) { 'nr349ct7889' } - let(:version_id) { 'v1' } + let(:version_id) { '1' } let(:file_name) { 'image.jp2' } let(:public_json) do { @@ -35,7 +35,7 @@ describe 'OPTIONS options' do it 'permits Range headers for all origins' do - options "/v2/file/#{druid}/#{version_id}/#{file_name}" + options "/v2/file/#{druid}/version/#{version_id}/#{file_name}" expect(response).to be_successful expect(response.headers['Access-Control-Allow-Origin']).to eq '*' expect(response.headers['Access-Control-Allow-Headers']).to include 'Range' @@ -52,12 +52,12 @@ before do allow_any_instance_of(FileController).to receive(:send_file) .with('spec/fixtures/nr/349/ct/7889/path/to/image.jp2', filename: 'path/to/image.jp2', disposition: :inline) - stub_request(:get, "https://purl.stanford.edu/#{druid}/#{version_id}.json") + stub_request(:get, "https://purl.stanford.edu/#{druid}/version/#{version_id}.json") .to_return(status: 200, body: public_json.to_json) end it 'returns a successful HTTP response' do - get "/v2/file/#{druid}/#{version_id}/#{file_name}" + get "/v2/file/#{druid}/version/#{version_id}/#{file_name}" expect(response).to be_successful expect(Cocina).to have_received(:find).with(druid, version_id) end @@ -65,14 +65,14 @@ describe 'GET missing file' do before do - stub_request(:get, "https://purl.stanford.edu/xf680rd3068/v1.json") + stub_request(:get, "https://purl.stanford.edu/xf680rd3068/version/1.json") .to_return(status: 200, body: public_json.to_json) end it 'returns a 400 HTTP response' do - get '/v2/file/xf680rd3068/v1/path/to/99999.jp2' + get '/v2/file/xf680rd3068/version/1/path/to/99999.jp2' expect(response).to have_http_status(:not_found) - expect(Cocina).to have_received(:find).with('xf680rd3068', 'v1') + expect(Cocina).to have_received(:find).with('xf680rd3068', '1') end end end