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

Wrap riiif initializer in a Reloader #4843

Merged
merged 1 commit into from
Mar 31, 2021
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
42 changes: 22 additions & 20 deletions .dassie/config/initializers/riiif.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
# frozen_string_literal: true
Riiif::Image.file_resolver = Riiif::HttpFileResolver.new
Riiif::Image.info_service = lambda do |id, _file|
# id will look like a path to a pcdm:file
# (e.g. rv042t299%2Ffiles%2F6d71677a-4f80-42f1-ae58-ed1063fd79c7)
# but we just want the id for the FileSet it's attached to.
ActiveSupport::Reloader.to_prepare do
Riiif::Image.file_resolver = Riiif::HttpFileResolver.new
Riiif::Image.info_service = lambda do |id, _file|
# id will look like a path to a pcdm:file
# (e.g. rv042t299%2Ffiles%2F6d71677a-4f80-42f1-ae58-ed1063fd79c7)
# but we just want the id for the FileSet it's attached to.

# Capture everything before the first slash
fs_id = id.sub(/\A([^\/]*)\/.*/, '\1')
resp = Hyrax::SolrService.get("id:#{fs_id}")
doc = resp['response']['docs'].first
raise "Unable to find solr document with id:#{fs_id}" unless doc
{ height: doc['height_is'], width: doc['width_is'], format: doc['mime_type_ssi'], channels: doc['alpha_channels_ssi'] }
end
# Capture everything before the first slash
fs_id = id.sub(/\A([^\/]*)\/.*/, '\1')
resp = Hyrax::SolrService.get("id:#{fs_id}")
doc = resp['response']['docs'].first
raise "Unable to find solr document with id:#{fs_id}" unless doc
{ height: doc['height_is'], width: doc['width_is'], format: doc['mime_type_ssi'], channels: doc['alpha_channels_ssi'] }
end

Riiif::Image.file_resolver.id_to_uri = lambda do |id|
Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url|
Rails.logger.info "Riiif resolved #{id} to #{url}"
Riiif::Image.file_resolver.id_to_uri = lambda do |id|
Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url|
Rails.logger.info "Riiif resolved #{id} to #{url}"
end
end
end

Riiif::Image.authorization_service = Hyrax::IIIFAuthorizationService
Riiif::Image.authorization_service = Hyrax::IIIFAuthorizationService

Riiif.not_found_image = Rails.root.join('app', 'assets', 'images', 'us_404.svg')
Riiif.unauthorized_image = Rails.root.join('app', 'assets', 'images', 'us_404.svg')
Riiif.not_found_image = Rails.root.join('app', 'assets', 'images', 'us_404.svg')
Riiif.unauthorized_image = Rails.root.join('app', 'assets', 'images', 'us_404.svg')

Riiif::Engine.config.cache_duration = 365.days
Riiif::Engine.config.cache_duration = 365.days
end
42 changes: 22 additions & 20 deletions lib/generators/hyrax/templates/config/initializers/riiif.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
# frozen_string_literal: true
Riiif::Image.file_resolver = Riiif::HttpFileResolver.new
Riiif::Image.info_service = lambda do |id, _file|
# id will look like a path to a pcdm:file
# (e.g. rv042t299%2Ffiles%2F6d71677a-4f80-42f1-ae58-ed1063fd79c7)
# but we just want the id for the FileSet it's attached to.
ActiveSupport::Reloader.to_prepare do
Riiif::Image.file_resolver = Riiif::HttpFileResolver.new
Riiif::Image.info_service = lambda do |id, _file|
# id will look like a path to a pcdm:file
# (e.g. rv042t299%2Ffiles%2F6d71677a-4f80-42f1-ae58-ed1063fd79c7)
# but we just want the id for the FileSet it's attached to.

# Capture everything before the first slash
fs_id = id.sub(/\A([^\/]*)\/.*/, '\1')
resp = Hyrax::SolrService.get("id:#{fs_id}")
doc = resp['response']['docs'].first
raise "Unable to find solr document with id:#{fs_id}" unless doc
{ height: doc['height_is'], width: doc['width_is'], format: doc['mime_type_ssi'], channels: doc['alpha_channels_ssi'] }
end
# Capture everything before the first slash
fs_id = id.sub(/\A([^\/]*)\/.*/, '\1')
resp = Hyrax::SolrService.get("id:#{fs_id}")
doc = resp['response']['docs'].first
raise "Unable to find solr document with id:#{fs_id}" unless doc
{ height: doc['height_is'], width: doc['width_is'], format: doc['mime_type_ssi'], channels: doc['alpha_channels_ssi'] }
end

Riiif::Image.file_resolver.id_to_uri = lambda do |id|
Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url|
Rails.logger.info "Riiif resolved #{id} to #{url}"
Riiif::Image.file_resolver.id_to_uri = lambda do |id|
Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url|
Rails.logger.info "Riiif resolved #{id} to #{url}"
end
end
end

Riiif::Image.authorization_service = Hyrax::IIIFAuthorizationService
Riiif::Image.authorization_service = Hyrax::IIIFAuthorizationService

Riiif.not_found_image = Rails.root.join('app', 'assets', 'images', 'us_404.svg')
Riiif.unauthorized_image = Rails.root.join('app', 'assets', 'images', 'us_404.svg')
Riiif.not_found_image = Rails.root.join('app', 'assets', 'images', 'us_404.svg')
Riiif.unauthorized_image = Rails.root.join('app', 'assets', 'images', 'us_404.svg')

Riiif::Engine.config.cache_duration = 365.days
Riiif::Engine.config.cache_duration = 365.days
end