-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #642 from IU-Libraries-Joint-Development/essi-2042…
…_ext_download ESSI-2042 Add extstore support to downloads controller
- Loading branch information
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
lib/extensions/hyrax/downloads_controller/external_storage.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Handle files from external storage | ||
module Extensions | ||
module Hyrax | ||
module DownloadsController | ||
module ExternalStorage | ||
def show | ||
if asset.content_location&.start_with?('s3://') | ||
ext_id = asset.content_location.split('/').last | ||
external_asset = ESSI.external_storage.get(ext_id) | ||
send_data external_asset.body.read, filename: ext_id | ||
else | ||
super | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe Hyrax::DownloadsController do | ||
routes { Hyrax::Engine.routes } | ||
|
||
let(:user) { FactoryBot.create(:user) } | ||
let(:resource) { FactoryBot.create(:file_set, user: user, title: ['Ext File'], content_location: content_location) } | ||
let(:content_location) { 's3://localhost:9000/essi-test/ext-store/12/34/ab/cd/1234abcd-original_file.ptif' } | ||
let(:identifier) { content_location.split('/').last } | ||
let(:data) { 'test data' } | ||
let(:ext_store_response) { double('S3 Response', body: StringIO.new(data)) } | ||
|
||
before { sign_in user } | ||
|
||
it 'handles requests for files with s3:// prefixed content location' do | ||
expect(ESSI.external_storage).to receive(:get).with(identifier) | ||
.and_return(ext_store_response) | ||
get :show, params: { id: resource.id } | ||
expect(response).to be_successful | ||
expect(response.body).to eq data | ||
end | ||
|
||
end |