From 6064275389997f27a6af151a008718319bf6ae28 Mon Sep 17 00:00:00 2001 From: Pascal Ernster <pascal.ernster@rub.de> Date: Wed, 14 Jun 2023 11:51:02 +0200 Subject: [PATCH] Do not merge this commit! This is just a quick and dirty summary of our changes for Anusha. --- .env.template | 1 + .env.template.development | 1 + hyrax/config/initializers/hyrax.rb | 16 +++------------- hyrax/config/initializers/hyrax_matomo.rb | 14 ++++++++++++++ hyrax/config/uv/uv.html | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 hyrax/config/initializers/hyrax_matomo.rb diff --git a/.env.template b/.env.template index 38261e9e..9b11e0c9 100644 --- a/.env.template +++ b/.env.template @@ -65,6 +65,7 @@ HYRAX_ANALYTICS_PROVIDER=matomo ANALYTICS_START_DATE=2022-02-18 MATOMO_SITE_ID= MATOMO_BASE_URL= +MATOMO_BASE_URL_SUFFIX="index.php" MATOMO_AUTH_TOKEN= # Hyrax application setting diff --git a/.env.template.development b/.env.template.development index 840bd371..3aa9000a 100644 --- a/.env.template.development +++ b/.env.template.development @@ -68,6 +68,7 @@ HYRAX_ANALYTICS_PROVIDER= ANALYTICS_START_DATE= MATOMO_SITE_ID= MATOMO_BASE_URL= +MATOMO_BASE_URL_SUFFIX="index.php" MATOMO_AUTH_TOKEN= # Hyrax application setting diff --git a/hyrax/config/initializers/hyrax.rb b/hyrax/config/initializers/hyrax.rb index deff604d..086eb2eb 100644 --- a/hyrax/config/initializers/hyrax.rb +++ b/hyrax/config/initializers/hyrax.rb @@ -131,21 +131,10 @@ Hyrax.config do |config| # # Default is false config.iiif_image_server = true - if ENV.fetch('IIIF_TO_SERVE_SSL_URLS', 'false') == 'true' - protocol = 'https' - else - protocol = 'http' - end - - if Rails.env.development? - port = ENV.fetch('PORT', 3000) - else - port = nil - end # Returns a URL that resolves to an image provided by a IIIF image server config.iiif_image_url_builder = lambda do |file_id, base_url, size, format| - Riiif::Engine.routes.url_helpers.image_url(file_id, host: base_url, size: size, protocol: protocol, port: port) + Riiif::Engine.routes.url_helpers.image_url(file_id, size: size, only_path: true) end # config.iiif_image_url_builder = lambda do |file_id, base_url, size, format| # "#{base_url}/downloads/#{file_id.split('/').first}" @@ -153,7 +142,8 @@ Hyrax.config do |config| # Returns a URL that resolves to an info.json file provided by a IIIF image server config.iiif_info_url_builder = lambda do |file_id, base_url| - uri = Riiif::Engine.routes.url_helpers.info_url(file_id, host: base_url, protocol: protocol, port: port) + uri = Riiif::Engine.routes.url_helpers.info_url(file_id, only_path: true) + uri.sub(/\Ahttp:/, 'https:') uri.sub(%r{/info\.json\Z}, '') end diff --git a/hyrax/config/initializers/hyrax_matomo.rb b/hyrax/config/initializers/hyrax_matomo.rb new file mode 100644 index 00000000..dadb2824 --- /dev/null +++ b/hyrax/config/initializers/hyrax_matomo.rb @@ -0,0 +1,14 @@ +# Make the base URL suffix of the external matomo instance configurable. +# This is required because +# a) by default, Faraday does not follow HTTP redirects, and +# b) the code in the Hyrax 3.5.0 code doesn't work if the Matomo instance's webserver redirects / to /index.php +# See also https://github.com/samvera/hyrax/issues/5593 and https://github.com/samvera/hyrax/issues/5846 +Rails.configuration.to_prepare do + Hyrax::Analytics::Matomo::Config.class_eval do + def get(params) + response = Faraday.get(config.base_url+ENV.fetch("MATOMO_BASE_URL_SUFFIX","index.php"), params) + return [] if response.status != 200 + JSON.parse(response.body) + end + end +end diff --git a/hyrax/config/uv/uv.html b/hyrax/config/uv/uv.html index c8e8eced..e01b72dd 100644 --- a/hyrax/config/uv/uv.html +++ b/hyrax/config/uv/uv.html @@ -8,7 +8,7 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <link rel="icon" href="favicon.ico"> <link rel="stylesheet" type="text/css" href="uv.css"> - <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script> + <script src="lib/hls.min.js"></script> <script type="text/javascript" src="lib/offline.js"></script> <script type="text/javascript" src="helpers.js"></script> <style> -- GitLab