Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
🐛 Check for pdf extension
Browse files Browse the repository at this point in the history
This commit will add a check for the file set's extension (label)
instead of solely relying on the mime type. This will allow us to know
if it's a PDF (as best as we can anyway) even if CharacterizeJob did not
run.

Also, downgraded the version of simple_form because it was causing
crashes in development.
  • Loading branch information
kirkkwang committed Nov 22, 2023
1 parent 5273bbb commit fa3d572
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ GEM
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simple_form (5.3.0)
simple_form (5.1.0)
actionpack (>= 5.2)
activemodel (>= 5.2)
simplecov (0.16.1)
Expand Down
21 changes: 13 additions & 8 deletions app/helpers/pdf_js_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
module PdfJsHelper
def pdf_js_url(file_set_presenter)
# assumes that the download path exists if the file set has been characterized
path = if file_set_presenter.mime_type
hyrax.download_path(file_set_presenter.id)
else
file_set_presenter.solr_document["import_url_ssim"].first
end
url = if file_set_presenter.mime_type
"/pdf.js/web/viewer.html?file=#{hyrax.download_path(file_set_presenter.id)}"
else
file_set_presenter.solr_document["import_url_ssim"].first
end

"/pdf.js/web/viewer.html?file=#{path}##{query_param}"
url + "##{query_param}"
end

def pdf_file_set_presenter(presenter)
Expand All @@ -22,14 +22,19 @@ def pdf_file_set_presenter(presenter)
end

def first_file_set_pdf(presenter)
pdf_file_set_presenters = presenter.file_set_presenters.select(&:pdf?)
reader, archival = pdf_file_set_presenters.partition do |fsp|
reader, archival = pdf_file_set_presenters(presenter.file_set_presenters).partition do |fsp|
fsp.solr_document["import_url_ssim"]&.first&.include? "READER"
end

reader.first || archival.first
end

def pdf_file_set_presenters(presenters)
presenters.select(&:pdf?) || presenters.select do |file_set_presenter|
file_set_presenter.solr_document["label_ssi"].downcase.end_with? ".pdf"
end
end

def representative_presenter(presenter)
presenter.file_set_presenters.find { |file_set_presenter| file_set_presenter.id == presenter.representative_id }
end
Expand Down

0 comments on commit fa3d572

Please sign in to comment.