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

Fix duplicate thumbnails for PDFs #2254

Merged
merged 2 commits into from
Jun 24, 2024
Merged
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
40 changes: 32 additions & 8 deletions app/services/hyrax/file_set_derivatives_service_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
# frozen_string_literal: true

# OVERRIDE Hyrax v5.0.0rc2 to increase the size of thumbnails

# OVERRIDE Hyrax v5.0.0rc2
# - to increase the size of thumbnails
# - add method missing_thumbnail? for methods which do both thumbnail AND another derivative
# (We were getting duplicate Hyrax::Metadata for thumbnails due to failing and rerunning derivative jobs.)
# - comment out failing method extract_full_text for PDF derivatives
module Hyrax
module FileSetDerivativesServiceDecorator
# @see https://github.com/samvera/hydra-derivatives/blob/main/lib/hydra/derivatives/processors/video/config.rb#L59
DEFAULT_VIDEO_SIZE = '320x240'

## Override initialize to add method missing_thumbnail?
# We were getting duplicate Hyrax::Metadata for thumbnails due to failing and rerunning derivative jobs.
def initialize(file_set)
super
@fs = if @file_set.is_a?(Hyrax::FileMetadata)
Hyrax.query_service.find_by(id: @file_set.file_set_id)
else
@file_set
end
end

def missing_thumbnail?
@fs.thumbnail.nil?
end

def create_pdf_derivatives(filename)
Hydra::Derivatives::PdfDerivatives.create(filename, outputs: [{ label: :thumbnail,
format: 'jpg',
size: '676x986',
url: derivative_url('thumbnail'),
layer: 0 }])
extract_full_text(filename, uri)

# @todo: Fix extract_full_text & wrap above in if missing_thumbnail? check
# commented out because it is failing resulting in RuntimeError (blank file detected)
# in ValkyriePersistDerivatives
# extract_full_text(filename, uri)
end

def create_office_document_derivatives(filename)
Hydra::Derivatives::DocumentDerivatives.create(filename, outputs: [{ label: :thumbnail,
format: 'jpg',
size: '600x450>',
url: derivative_url('thumbnail'),
layer: 0 }])
if missing_thumbnail?
Hydra::Derivatives::DocumentDerivatives.create(filename, outputs: [{ label: :thumbnail,
format: 'jpg',
size: '600x450>',
url: derivative_url('thumbnail'),
layer: 0 }])
end
extract_full_text(filename, uri)
end

Expand Down
Loading