Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes ACHYDRA-967: Now generating proper wowza streaming URLs for access copy paths that start with either file:/ or file:/// #296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ def image_url(size = 256)
"#{Rails.application.secrets.iiif[:urls].sample}/#{fetch(:fedora3_pid_ssi)}/full/!#{size},#{size}/0/native.jpg"
end

def file_uri_ds_location_to_file_path(file_uri_ds_location)
return nil if file_uri_ds_location.nil?
Addressable::URI.unencode(file_uri_ds_location).gsub(%r{^file:/+}, '/')
end

def wowza_media_url(request)
raise ArgumentError, 'Request object invalid' unless request.is_a?(ActionDispatch::Request)
return unless playable?
Expand All @@ -170,7 +175,7 @@ def wowza_media_url(request)
wowza_config = Rails.application.secrets[:wowza]
raise 'Missing wowza config' unless wowza_config

access_copy_location = fetch('access_copy_location_ssi', nil)&.gsub(/^file:/, '')
access_copy_location = file_uri_ds_location_to_file_path(fetch('access_copy_location_ssi', nil))

return unless access_copy_location

Expand Down
20 changes: 20 additions & 0 deletions spec/models/solr_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,24 @@
end
end
end

describe '#file_uri_ds_location_to_file_path' do
let(:document) do
described_class.new(
'id' => '10.7916/TEST123'
)
end
let(:file_path) { '/path/to/a & b.mp4' }
let(:url_encoded_file_path) { file_path.gsub(' ', '%20').gsub('&', '%26') }
let(:single_slash_file_uri) { "file:#{url_encoded_file_path}" }
let(:triple_slash_file_uri) { "file://#{url_encoded_file_path}" }

it 'properly converts a ds location that uses a single slash file URI' do
expect(document.file_uri_ds_location_to_file_path(single_slash_file_uri)).to eq(file_path)
end

it 'properly converts a ds location that uses a triple slash file URI' do
expect(document.file_uri_ds_location_to_file_path(triple_slash_file_uri)).to eq(file_path)
end
end
end