Skip to content

Commit

Permalink
Merge pull request #1231 from sul-dlss/update-version-paths
Browse files Browse the repository at this point in the history
Update paths for versionable routes
  • Loading branch information
justinlittman authored Aug 7, 2024
2 parents f0f7cca + 8172a77 commit d009ec7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/models/cocina.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/models/cocina_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions spec/requests/versioned_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'
Expand All @@ -52,27 +52,27 @@
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
end

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

0 comments on commit d009ec7

Please sign in to comment.