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

🎁 Only run thumbnail derivatives on thumbnails #684

Merged
merged 1 commit into from
Nov 29, 2023
Merged
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
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ GIT

GIT
remote: https://github.com/scientist-softserv/iiif_print.git
revision: e42cfd2a6d9b0aac9901084625ee1e1a0a3ccb6d
revision: 5c5fa6880b3dc22beed738cfcba7af57b698ac36
branch: main
specs:
iiif_print (1.0.0)
blacklight_iiif_search (>= 1.0, < 3.0)
derivative-rodeo (~> 0.5)
hyrax (>= 2.5, < 6)
nokogiri (>= 1.13.2)
rails (>= 5.0, < 8.0)
rdf-vocab (~> 3.0)

GIT
Expand Down
9 changes: 9 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ class Application < Rails::Application
Rails.configuration.cache_classes ? require(c) : load(c)
end

# See: https://github.com/scientist-softserv/adventist-dl/issues/676
IiifPrint::DerivativeRodeoService.named_derivatives_and_generators_filter =
->(file_set:, filename:, named_derivatives_and_generators:) do
named_derivatives_and_generators.reject do |named_derivative, generators|
named_derivative != :thumbnail && filename.downcase.ends_with?(Hyku::THUMBNAIL_FILE_SUFFIX)
end
end
end

# resolve reloading issue in dev mode
Expand All @@ -121,4 +128,6 @@ class Application < Rails::Application
# copies tinymce assets directly into public/assets
config.tinymce.install = :copy
end

THUMBNAIL_FILE_SUFFIX = '.tn.jpg'
end
2 changes: 2 additions & 0 deletions config/initializers/iiif_print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@
if ENV.fetch('LOCAL_RODEO_LOG', 'false') == 'true'
FileUtils.mkdir_p(Rails.root.join('log').to_s)
DerivativeRodeo.config.logger = Logger.new(Rails.root.join("log/dr.log").to_s, level: Logger::DEBUG)
else
DerivativeRodeo.config.logger = Rails.logger
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
module IIIFManifest
module ManifestBuilderDecorator
module CanvasBuilderFactoryDecorator
THUMBNAIL_FILE_SUFFIX = '.tn.jpg'

def from(work)
composite_builder.new(
*file_set_presenters(work).map do |presenter|
next if presenter.label.downcase.end_with?(THUMBNAIL_FILE_SUFFIX) || !presenter.image?
next if presenter.label.downcase.end_with?(Hyku::THUMBNAIL_FILE_SUFFIX) || !presenter.image?
canvas_builder_factory.new(presenter, work)
end
)
Expand Down
36 changes: 36 additions & 0 deletions spec/config/application_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

# rubocop:disable RSpec/DescribeClass
RSpec.describe 'config/application.rb' do
# rubocop:enable RSpec/DescribeClass
describe 'IiifPrint::DerivativeRodeoService.named_derivatives_and_generators_filter' do
subject do
IiifPrint::DerivativeRodeoService
.named_derivatives_and_generators_filter
.call(file_set: file_set,
filename: filename,
named_derivatives_and_generators: named_derivatives_and_generators).keys
end

let(:file_set) { double('file_set') }
let(:named_derivatives_and_generators) do
IiifPrint::DerivativeRodeoService.named_derivatives_and_generators_by_type.fetch(:image).deep_dup
end

context 'for a thumbnail file' do
let(:filename) { 'image.TN.jpg' }

it 'will only generate a thumbnail' do
expect(subject).to eq [:thumbnail]
end
end

context 'for a non-thumbnail file' do
let(:filename) { 'image.jpg' }

it 'will generate all derivatives' do
expect(subject).to eq %i[thumbnail json xml txt]
end
end
end
end
Loading