Skip to content

Commit

Permalink
Merge pull request #1114 from LafayetteCollegeLibraries/develop
Browse files Browse the repository at this point in the history
2024.4
  • Loading branch information
rococodogs authored Mar 26, 2024
2 parents 5c961a9 + 2863209 commit 505856e
Show file tree
Hide file tree
Showing 22 changed files with 545 additions and 478 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# changelog

## [2024.4] - 2024-03-26

### enhancements ✨
- Refactored derivatives code to ensure PDFs are being OCR'd (and generally make the process a bit more legible) (#1010)

### updates 📈
- Bulkrax to 5.5.1 (#1113)

### bug fixes 🐞
- **All works / My works** dashboard navtabs work again (#1113)
- Removed `eduPersonEntitlement` values from cookied CAS attributes (#1115)


## [2024.3] - 2024-03-15

### bug fixes 🐞
Expand Down Expand Up @@ -910,6 +923,7 @@ fixes:

Initial pre-release (live on ldr.stage.lafayette.edu)

[2024.4]: https://github.com/LafayetteCollegeLibraries/spot/releases/tag/2024.4
[2024.3]: https://github.com/LafayetteCollegeLibraries/spot/releases/tag/2024.3
[2024.2]: https://github.com/LafayetteCollegeLibraries/spot/releases/tag/2024.2
[2024.1]: https://github.com/LafayetteCollegeLibraries/spot/releases/tag/2024.1
Expand Down
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ gem 'bootsnap', '~> 1.17', require: false

# Bulkrax for batch ingesting objects
gem 'browse-everything', '~> 1.1.2'
gem 'bulkrax', '~> 5.3.0'
gem 'bulkrax', '~> 5.5.1'

# This needs to be here if we want to compile our own JS
# (there's like a single coffee-script file still remaining in hyrax)
Expand Down Expand Up @@ -138,6 +138,10 @@ gem 'sprockets-es6', '~> 0.9.2'
# @todo remove when Hyrax 3.5.1 or 3.6 (whichever includes it) drops
gem 'redlock', '>= 0.1.2', '< 2.0'

# This is locked in hydra_editor > v6 to prevent an update
# that throws off how forms are built in Hyrax.
gem 'simple_form', '< 5.2'

# development dependencies (not as necessary to lock down versions here)
group :development do
# Seed data
Expand Down
47 changes: 22 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ GEM
babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6)
execjs (~> 2.0)
bagit (0.4.5)
bagit (0.4.6)
docopt (~> 0.5.0)
validatable (~> 1.6)
bcp47 (0.3.3)
Expand Down Expand Up @@ -176,10 +176,9 @@ GEM
signet (~> 0.8)
typhoeus
builder (3.2.4)
bulkrax (5.3.0)
bulkrax (5.5.1)
bagit (~> 0.4)
coderay
dry-monads (~> 1.4.0)
iso8601 (~> 0.9.0)
kaminari
language_list (~> 1.2, >= 1.2.1)
Expand Down Expand Up @@ -219,7 +218,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.2.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crack (0.4.5)
rexml
Expand All @@ -230,7 +229,7 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.3.3)
date (3.3.4)
declarative (0.0.20)
declarative-builder (0.1.0)
declarative-option (< 0.2.0)
Expand Down Expand Up @@ -530,7 +529,7 @@ GEM
valkyrie (~> 2, >= 2.1.1)
hyrax-spec (0.3.2)
rspec (~> 3.6)
i18n (1.14.1)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
iiif_manifest (1.3.1)
Expand Down Expand Up @@ -652,45 +651,43 @@ GEM
mailboxer (0.15.1)
carrierwave (>= 0.5.8)
rails (>= 5.0.0)
marcel (1.0.2)
marcel (1.0.4)
matrix (0.4.2)
memoist (0.16.2)
method_source (1.0.0)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0218.1)
mini_magick (4.12.0)
mini_mime (1.1.2)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.18.1)
minitest (5.22.3)
msgpack (1.7.1)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.3.0)
multipart-post (2.4.0)
namae (1.1.1)
nest (3.2.0)
redic
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
net-imap (0.3.6)
net-imap (0.4.10)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
net-protocol (0.2.2)
timeout
net-smtp (0.3.3)
net-smtp (0.4.0.1)
net-protocol
nio4r (2.5.9)
nio4r (2.7.0)
noid (0.9.0)
noid-rails (3.0.3)
actionpack (>= 5.0.0, < 7)
noid (~> 0.9)
nokogiri (1.15.3)
nokogiri (1.15.6)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.3-arm64-darwin)
racc (~> 1.4)
non-digest-assets (2.2.0)
activesupport (>= 5.2, < 7.1)
sprockets (>= 2.0, < 5.0)
Expand Down Expand Up @@ -738,7 +735,7 @@ GEM
rdf
raabro (1.4.0)
racc (1.7.3)
rack (2.2.8)
rack (2.2.8.1)
rack-cas (0.16.1)
addressable (~> 2.3)
nokogiri (~> 1.5)
Expand Down Expand Up @@ -980,7 +977,7 @@ GEM
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simple_form (5.2.0)
simple_form (5.1.0)
actionpack (>= 5.2)
activemodel (>= 5.2)
simplecov (0.21.2)
Expand Down Expand Up @@ -1036,10 +1033,10 @@ GEM
temple (0.10.3)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
thor (1.3.0)
thor (1.3.1)
thread_safe (0.3.6)
tilt (2.3.0)
timeout (0.4.0)
timeout (0.4.1)
tinymce-rails (5.10.7.1)
railties (>= 3.1.1)
turbolinks (5.2.1)
Expand Down Expand Up @@ -1090,15 +1087,14 @@ GEM
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
websocket (1.2.10)
websocket-driver (0.7.5)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.8)
zeitwerk (2.6.13)

PLATFORMS
arm64-darwin-22
ruby

DEPENDENCIES
Expand All @@ -1112,7 +1108,7 @@ DEPENDENCIES
blacklight_range_limit (~> 6.3.3)
bootsnap (~> 1.17)
browse-everything (~> 1.1.2)
bulkrax (~> 5.3.0)
bulkrax (~> 5.5.1)
byebug (~> 11.1.3)
capybara (~> 3.38)
capybara-screenshot (~> 1.0.26)
Expand Down Expand Up @@ -1157,6 +1153,7 @@ DEPENDENCIES
shoulda-matchers (~> 4)
sidekiq (~> 5.2.9)
sidekiq-cron (~> 1.9.1)
simple_form (< 5.2)
simplecov (~> 0.21.2)
slack-ruby-client (~> 0.14.6)
spring (~> 2.1.1)
Expand Down
14 changes: 14 additions & 0 deletions app/services/spot/derivatives/base_derivative_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true
module Spot
module Derivatives
# Base class that other derivative services can inherit from
class BaseDerivativeService < ::Hyrax::DerivativeService
delegate :audio_mime_types,
:image_mime_types,
:pdf_mime_types,
:office_document_mime_types,
:video_mime_types,
to: :FileSet
end
end
end
21 changes: 0 additions & 21 deletions app/services/spot/derivatives/base_derivatives_service.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,51 @@

module Spot
module Derivatives
# Creates access_master derivatives for all image-based works.
# Intended to be run as part of a subset within {Spot::ImageDerivativesService}
# and needs to respond to :cleanup_derivatives and :create_derivatives (the
# latter receives a source filename as a parameter).
# Creates pyramidal TIFF copies of Images for serving via IIIF. Pyramidal TIFFs contain
# layers at different resolutions which makes their use in a deep-zooming IIIF application
# (ie. UniversalViewer) more efficient.
#
# When the AWS_IIIF_ASSET_BUCKET environment variable is present, this will
# write the file to a defined S3 bucket and remove the local copy.
# This generates the file locally and then uploads to an S3 bucket defined by the
# AWS_IIIF_ASSET_BUCKET environment variable. The local copy is deleted afterwards.
#
# @example usage
# file_set = FileSet.find(id: 'abc123def')
# src_path = Rails.root.join('tmp', 'uploads', more_path, 'original-file.tif')
# Spot::Derivatives::AccessMasterService.new(file_set).create_derivatives(src_path)
class AccessMasterService < BaseDerivativesService
# Determines which cleanup method to use based on whether or not AWS related
# variables are present in ENV
#
# @return [void]
def cleanup_derivatives
use_s3? ? cleanup_s3_derivatives : cleanup_local_derivatives
end

# Deletes the local access_master derivative if it exists
#
# @return [void]
def cleanup_local_derivatives
FileUtils.rm_f(derivative_path) if File.exist?(derivative_path)
end
# These derivatives are created for an FileSets that include Image mime_types.
#
# @see https://www.loc.gov/preservation/digital/formats/fdd/fdd000237.shtml
class IiifAccessCopyService < BaseDerivativeService
class_attribute :derivative_key_template
self.derivative_key_template = '%s-access.tif'

# Deletes the derivative from the S3 bucket
# @todo maybe we should hang onto these when we delete + put them in a glacier grave?
# @return [void]
# @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#delete_object-instance_method
def cleanup_s3_derivatives
def cleanup_derivatives
s3_client.delete_object(bucket: s3_bucket, key: s3_derivative_key)
end

# Since we want to pass some extended options to the creation process,
# we'll use MiniMagick directly instead of Hydra::Derviatives::ImageDerivatives.
# If AWS ENV variables are present, this will upload the generated file
# to an S3 bucket and then delete the local copy.
# Generates a pyramidal TIFF using ImageMagick (via MiniMagick gem)
# and uploads it to the S3 bucket.
#
# @param [String,Pathname] filename the src path of the file
# @return [void]
def create_derivatives(filename)
output_dirname = File.dirname(derivative_path)
FileUtils.mkdir_p(output_dirname) unless File.directory?(output_dirname)

MiniMagick::Tool::Convert.new do |magick|
magick << "#{filename}[0]"
# we need to use an array for each piece of this command; using a string will cause an error
magick.merge! %w[-define tiff:tile-geometry=128x128 -compress jpeg]
magick << "ptif:#{derivative_path}"
MiniMagick::Tool::Convert.new do |convert|
convert.merge!(
[
"#{filename}[0]",
"-define", "tiff:tile-geometry=128x128",
"-compress", "jpeg",
"ptif:#{derivative_path}"
]
)
end

return unless use_s3?
upload_derivative_to_s3

upload_derivative_to_s3 && cleanup_local_derivatives
FileUtils.rm_f(derivative_path) if File.exist?(derivative_path)
end

# copied from https://github.com/samvera/hyrax/blob/5a9d1be1/app/services/hyrax/file_set_derivatives_service.rb#L32-L37
Expand All @@ -73,18 +61,30 @@ def derivative_path
Hyrax::DerivativePath.derivative_path_for_reference(file_set, 'access.tif').to_s.gsub(/\.access\.tif$/, '')
end

# Only create pyramidal TIFFs if the source mime_type is an Image and if we defined
def valid?
if s3_bucket.blank?
Rails.logger.warn('Skipping IIIF Access Copy generation because the AWS_IIIF_ASSET_BUCKET environment variable is not defined.')
return false
end

image_mime_types.include?(mime_type)
end

private

def s3_bucket
ENV['AWS_IIIF_ASSET_BUCKET']
end

# We're using AWS credentials stored within the App/Sidekiq services for authentication,
# so the Aws::S3::Client will pick them up ambiently.
def s3_client
@s3_client ||= Aws::S3::Client.new
end

def s3_derivative_key
"#{file_set.id}-access.tif"
derivative_key_template % file_set.id
end

def upload_derivative_to_s3
Expand All @@ -100,10 +100,6 @@ def upload_derivative_to_s3
}
)
end

def use_s3?
s3_bucket.present?
end
end
end
end
Loading

0 comments on commit 505856e

Please sign in to comment.