Skip to content

Commit

Permalink
Merge pull request #642 from IU-Libraries-Joint-Development/essi-2042…
Browse files Browse the repository at this point in the history
…_ext_download

ESSI-2042 Add extstore support to downloads controller
  • Loading branch information
dlpierce authored Dec 16, 2024
2 parents 9915840 + 9e46f71 commit 474e560
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
Mime::Type.register "application/universalviewer", :uv
Mime::Type.register "image/jp2", :jp2
Mime::Type.register "text/json", :iiif
Mime::Type.register "image/tiff", :ptif
3 changes: 3 additions & 0 deletions lib/extensions/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def attribute_will_change!(attr)
end
end

# external storage download support
Hyrax::DownloadsController.prepend Extensions::Hyrax::DownloadsController::ExternalStorage

# extracted text support
Hyrax::DownloadsController.prepend Extensions::Hyrax::DownloadsController::ExtractedText
Hyrax::FileSetPresenter.include Extensions::Hyrax::FileSetPresenter::ExtractedText
Expand Down
18 changes: 18 additions & 0 deletions lib/extensions/hyrax/downloads_controller/external_storage.rb
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
24 changes: 24 additions & 0 deletions spec/controllers/hyrax/downloads_controller_spec.rb
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

0 comments on commit 474e560

Please sign in to comment.