Skip to content

Commit

Permalink
Use file controller for v2 file path
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-collier committed Aug 1, 2024
1 parent fc859bc commit 4161298
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 148 deletions.
8 changes: 6 additions & 2 deletions app/controllers/file_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def disposition
end

def file_params
params.permit(:id, :file_name, :download)
params.permit(:id, :file_name, :download, :version_id)
end

# called when CanCan::AccessDenied error is raised, typically by authorize!
Expand Down Expand Up @@ -74,6 +74,10 @@ def current_file
end

def cocina
@cocina ||= Cocina.find(params[:id])
@cocina ||= Cocina.find(params[:id], version)
end

def version
params[:version_id] || :head
end
end
84 changes: 0 additions & 84 deletions app/controllers/v2/versions_controller.rb

This file was deleted.

6 changes: 2 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

constraints id: druid_regex do
get '/file/:id/*file_name' => 'file#show', format: false, as: :file
get '/v2/file/:id/:version_id/*file_name', to: 'file#show', format: false, constraints: { version_id: /v\d+/ }
options '/file/:id/*file_name', to: 'file#options', format: false
options '/v2/file/:id/:version_id/*file_name', to: 'file#options', format: false, constraints: { version_id: /v\d+/ }
get '/file/app/:id/*file_name' => 'webauth#login_file', format: false
get '/file/auth/:id/*file_name' => 'webauth#login_file', format: false, as: :auth_file
get '/file/auth/:id' => 'webauth#login_object', format: false, as: :auth_object
Expand All @@ -16,10 +18,6 @@
get '/file/app/druid::id/*file_name' => 'webauth#login_file', format: false
get '/file/auth/druid::id/*file_name' => 'webauth#login_file', format: false
get '/file/auth/druid::id' => 'webauth#login_object', format: false

namespace 'v2' do
get '/file/:id/:version_id/*file_name', to: 'versions#show', format: false, constraints: { version_id: /v\d+/ }
end
end

if Settings.features.streaming_media
Expand Down
56 changes: 0 additions & 56 deletions spec/controllers/v2/versions_controller_spec.rb

This file was deleted.

6 changes: 4 additions & 2 deletions spec/requests/versioned_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

describe 'OPTIONS options' do
it 'permits Range headers for all origins' do
options "/file/#{druid}/#{version_id}/#{file_name}"
options "/v2/file/#{druid}/#{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 Down Expand Up @@ -69,20 +69,22 @@
end

before do
allow_any_instance_of(V2::VersionsController).to receive(:send_file)
allow_any_instance_of(FileController).to receive(:send_file)
.with('spec/fixtures/nr/349/ct/7889/path/to/image.jp2', disposition: :inline)
end

it 'returns a successful HTTP response' do
get "/v2/file/#{druid}/#{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
it 'returns a 400 HTTP response' do
get '/v2/file/xf680rd3068/v1/path/to/99999.jp2'
expect(response).to have_http_status(:not_found)
expect(Cocina).to have_received(:find).with('xf680rd3068', 'v1')
end
end
end

0 comments on commit 4161298

Please sign in to comment.