From 8e4e4404069159fc8a3829ab4372bf64b94118e3 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 26 Jan 2024 15:59:22 -0400 Subject: [PATCH 1/2] Allow CORS access. --- src/Controller/V3/ManifestController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Controller/V3/ManifestController.php b/src/Controller/V3/ManifestController.php index 853df2d..77e29ce 100644 --- a/src/Controller/V3/ManifestController.php +++ b/src/Controller/V3/ManifestController.php @@ -44,7 +44,11 @@ public function build(string $parameter_name, RouteMatchInterface $route_match) return (new JsonResponse( $this->serializer->serialize($_entity, 'iiif-p-v3'), 200, - [], + [ + 'Access-Control-Allow-Credentials' => 'true', + 'Access-Control-Allow-Origin' => '*', + 'Access-Control-Allow-Methods' => 'GET', + ], TRUE )); } From e818f977aef6b0788470b197ed0eaf29ea499069 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 26 Jan 2024 16:13:20 -0400 Subject: [PATCH 2/2] Allow more flexible relative-URL interpretation. --- README.md | 9 +++++++++ src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a36b42..9a14b88 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,15 @@ There are some environment variables to help integrate with IIIF Image APIs, in Presently, we indicate `level2` compliance for each IIIF Image API endpoint. +As a point of convenience, it is possible to specify the `IIIF_IMAGE_V*_SLUG` +values using `base:`, as used by +[Drupal's `Url::fromUri()`](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/function/Url%3A%3AfromUri/10). +For example, if you are using a proxy to make a `/iiif/2` path for a IIIF-I v2 +endpoint, such that your slug would be +`https://{your hostname}/iiif/2/{identifier}`, then you can instead use +`base:/iiif/2/{identifier}` to configure the reference more explicitly relative +to the hostname used to access the site. + ## Troubleshooting/Issues Having problems or solved one? contact diff --git a/src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php b/src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php index 29ead87..48d0ba3 100644 --- a/src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php +++ b/src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php @@ -3,6 +3,7 @@ namespace Drupal\iiif_presentation_api\EventSubscriber\V3; use Drupal\Component\Plugin\PluginManagerInterface; +use Drupal\Core\Url; use Drupal\file\FileInterface; use Drupal\iiif_presentation_api\Event\V3\ImageBodyEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -75,13 +76,13 @@ protected function getBody(?string $slug, FileInterface $file, array $extra = [] '{identifier}' => rawurlencode($id_plugin->getIdentifier($file)), ]); return [ - 'id' => "{$base_id}/full/{$size}/0/default.jpg", + 'id' => Url::fromUri("{$base_id}/full/{$size}/0/default.jpg", ['absolute' => TRUE])->toString(), 'type' => 'Image', 'format' => 'image/jpeg', 'service' => [ [ // @todo Add in auth in some manner. - 'id' => $base_id, + 'id' => Url::fromUri($base_id, ['absolute' => TRUE])->toString(), ] + $extra, ], ];