Skip to content

Commit

Permalink
Correctly pass mime_type
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Sep 6, 2023
1 parent 4ca6765 commit 893f597
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def send_file_contents_valkyrie(file_set)
response.headers["Accept-Ranges"] = "bytes"
self.status = 200
use = params.fetch(:file, :original_file).to_sym
# mime_type param is not allowed
mime_type = params.permit(:mime_type)
mime_type = params[:mime_type]
file_metadata = find_file_metadata(file_set: file_set, use: use, mime_type: mime_type)
return unless stale?(last_modified: file_metadata.updated_at, template: false)

Expand Down Expand Up @@ -64,17 +63,14 @@ def prepare_file_headers_valkyrie(metadata:, file:, inline: false)

def find_file_metadata(file_set:, use: :original_file, mime_type: nil)
if mime_type.nil?
begin
use = :thumbnail_file if use == :thumbnail
use = Hyrax::FileMetadata::Use.uri_for(use: use)
rescue ArgumentError
raise Hyrax::ObjectNotFoundError
end
use = :thumbnail_file if use == :thumbnail
use = Hyrax::FileMetadata::Use.uri_for(use: use)
results = Hyrax.custom_queries.find_many_file_metadata_by_use(resource: file_set, use: use)
else
files = Hyrax.custom_queries.find_files(file_set: file_set)
results = [files.find { |f| f.mime_type == mime_type}]
end

results.first || raise(Hyrax::ObjectNotFoundError)
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/views/hyrax/file_sets/media_display/_audio.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div>
<h2 class="sr-only"><%= t('hyrax.file_set.show.downloadable_content.heading') %></h2>
<audio controls="controls" class="audiojs" style="width:100%" controlsList="nodownload" preload="auto">
<source src="<%= hyrax.download_path(file_set, file: 'ogg') %>" type="audio/ogg" />
<source src="<%= hyrax.download_path(file_set, file: 'mp3') %>" type="audio/mpeg" />
<source src="<%= hyrax.download_path(file_set, file: 'ogg', mime_type: 'audio/ogg') %>" type="audio/ogg" />
<source src="<%= hyrax.download_path(file_set, file: 'mp3', mime_type: 'audio/mpeg') %>" type="audio/mpeg" />
<%= t('hyrax.file_set.show.downloadable_content.audio_tag_not_supported') %>
</audio>
<%= link_to t('hyrax.file_set.show.downloadable_content.audio_link'),
Expand All @@ -15,8 +15,8 @@
<% else %>
<div>
<audio controls="controls" class="audiojs" style="width:100%" controlsList="nodownload" preload="auto">
<source src="<%= hyrax.download_path(file_set, file: 'ogg') %>" type="audio/ogg" />
<source src="<%= hyrax.download_path(file_set, file: 'mp3') %>" type="audio/mpeg" />
<source src="<%= hyrax.download_path(file_set, file: 'ogg', mime_type: 'audio/ogg') %>" type="audio/ogg" />
<source src="<%= hyrax.download_path(file_set, file: 'mp3', mime_type: 'audio/mpeg') %>" type="audio/mpeg" />
<%= t('hyrax.file_set.show.downloadable_content.audio_tag_not_supported') %>
</audio>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/hyrax/file_sets/media_display/_video.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div>
<h2 class="sr-only"><%= t('hyrax.file_set.show.downloadable_content.heading') %></h2>
<video controls="controls" class="video-js vjs-default-skin" style="width:100%" data-setup="{}" controlsList="nodownload" preload="auto">
<source src="<%= hyrax.download_path(file_set, file: 'webm') %>" type="video/webm" />
<source src="<%= hyrax.download_path(file_set, file: 'mp4') %>" type="video/mp4" />
<source src="<%= hyrax.download_path(file_set, file: 'webm', mime_type: 'video/webm') %>" type="video/webm" />
<source src="<%= hyrax.download_path(file_set, file: 'mp4', mime_type: 'video/mp4') %>" type="video/mp4" />
<%= t('hyrax.file_set.show.downloadable_content.video_tag_not_supported') %>
</video>
<%= link_to t('hyrax.file_set.show.downloadable_content.video_link'),
Expand Down
1 change: 0 additions & 1 deletion spec/controllers/hyrax/downloads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
create(:file_with_work, user: user, content: original_file)
end
end

before do
allow(subject).to receive(:authorize!).and_return(true)
allow(subject).to receive(:workflow_restriction?).and_return(false)
Expand Down

0 comments on commit 893f597

Please sign in to comment.