Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyf committed Feb 23, 2024
1 parent ddf6138 commit fcec407
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions lib/iiif_print/split_pdfs/derivative_rodeo_splitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DerivativeRodeoSplitter
#
# @see IiifPrint::SplitPdfs::BaseSplitter
def self.call(filename, file_set:)
new(filename, file_set: file_set).split_files
new(filename, file_set: file_set).call
end

##
Expand Down Expand Up @@ -145,20 +145,49 @@ def rodeo_conformant_uri_exists?(uri)
private :rodeo_conformant_uri_exists?

##
# @return [Array<Strings>] the paths to each of the images split off from the PDF.
# @return [Array<Strings>] the local paths to each of the images split off from the PDF.
def call
# TODO: Could we off-load the copy to another job? I'm afraid of the "cost" of copying
# a large number of files.
copy(split_files)
end

private

##
# @return [Array<DerivativeRodeo::StorageLocations::BaseLocation>]
def split_files
DerivativeRodeo::Generators::PdfSplitGenerator.new(
input_uris: [input_uri],
output_location_template: output_location_template,
preprocessed_location_template: preprocessed_location_template
).generated_files.map(&:file_path)
).generated_files
rescue => e
message = "#{self.class}##{__method__} encountered `#{e.class}' “#{e}” for " \
"input_uri: #{input_uri.inspect}, " \
"output_location_template: #{output_location_template.inspect}, and " \
"preprocessed_location_template: #{preprocessed_location_template.inspect}."
exception = RuntimeError.new(message)
exception.set_backtrace(e.backtrace)
DerivativeRodeo.logger.error(message)
raise exception
end

##
# @param [Array<DerivativeRodeo::StorageLocations::BaseLocation>]
# @return [Array<String>]
def copy(generated_files)
DerivativeRodeo::Generators::CopyGenerator.new(
input_uris: generated_files.map(&:file_uri),
output_location_template: output_location_template
).generated_files.map(&:file_path)
rescue => e
message = "#{self.class}##{__method__} encountered `#{e.class}' “#{e}” for " \
"input_uri: #{@input_uri.inspect}, " \
"output_location_template: #{output_location_template.inspect}"
exception = RuntimeError.new(message)
exception.set_backtrace(e.backtrace)
DerivativeRodeo.logger.error(message)
raise exception
end
end
Expand Down

0 comments on commit fcec407

Please sign in to comment.