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 23, 2023
1 parent 5273bbb commit d73a07b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ gem 'iiif_print', git: 'https://github.com/scientist-softserv/iiif_print.git', b
gem 'order_already'
gem 'redis', '~> 4.0'
gem 'redlock', '~> 1.2.1'
# locking to 5.1.0 because it was throwing errors on 5.3.0 in development
gem 'simple_form', '5.1.0'
3 changes: 2 additions & 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 Expand Up @@ -1225,6 +1225,7 @@ DEPENDENCIES
secure_headers
selenium-webdriver
sentry-raven
simple_form (= 5.1.0)
simplecov
solr_wrapper (~> 2.0)
spring (~> 1.7)
Expand Down
25 changes: 15 additions & 10 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 @@ -18,18 +18,23 @@ def pdf_file_set_presenter(presenter)
# Commenting this line out because even PDFs that were not split will still have a representative media
# which will be used first in this logic, consider uncommenting once all imports finish
# representative_presenter(presenter) ||
first_file_set_pdf(presenter)
external_pdf(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|
def external_pdf(presenter)
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?).presence || 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
6 changes: 5 additions & 1 deletion app/presenters/hyku/work_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ def video_embed_viewer

def pdf_viewer?
return unless Flipflop.default_pdf_viewer?
return unless file_set_presenters.any?(&:pdf?)
return unless file_set_presenters.any?(&:pdf?) || pdf_extension?

# If all of the member_presenters are file_set presenters, return true
# this also means that there are no child works
member_presenters.all? { |presenter| presenter.is_a? Hyrax::FileSetPresenter }
end

def pdf_extension?
file_set_presenters.any? { |fsp| fsp.label.downcase.end_with?('.pdf') }
end

def viewer?
iiif_viewer? || video_embed_viewer? || pdf_viewer?
end
Expand Down

0 comments on commit d73a07b

Please sign in to comment.