From 5223e920d9b16761360b78fe45333e7710eef59f Mon Sep 17 00:00:00 2001 From: Donald Gray Date: Mon, 24 Jun 2024 15:57:50 +0100 Subject: [PATCH] Do not include ImageService3 on v2 manifests --- .../Integration/ManifestHandlingTests.cs | 23 ++++++++++++++ .../Integration/NamedQueryTests.cs | 20 ++++++++++++- .../Infrastructure/IIIF/IIIFCanvasFactory.cs | 30 ++++++++++++------- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/protagonist/Orchestrator.Tests/Integration/ManifestHandlingTests.cs b/src/protagonist/Orchestrator.Tests/Integration/ManifestHandlingTests.cs index a68ff7546..729e02479 100644 --- a/src/protagonist/Orchestrator.Tests/Integration/ManifestHandlingTests.cs +++ b/src/protagonist/Orchestrator.Tests/Integration/ManifestHandlingTests.cs @@ -237,6 +237,29 @@ public async Task Get_ManifestForImage_ReturnsManifest() response.Headers.CacheControl.MaxAge.Should().BeGreaterThan(TimeSpan.FromSeconds(2)); } + [Fact] + public async Task Get_ManifestForImage_V2_ReturnsManifest_WithoutIIIFImage3Services() + { + // Arrange + var id = AssetIdGenerator.GetAssetId(); + await dbFixture.DbContext.Images.AddTestAsset(id, origin: "testorigin", imageDeliveryChannels: imageDeliveryChannels); + await dbFixture.DbContext.SaveChangesAsync(); + + var path = $"iiif-manifest/v2/{id}"; + + // Act + var response = await httpClient.GetAsync(path); + + // Assert + var json = await response.Content.ReadAsStringAsync(); + json.Should().NotContain("ImageService3"); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + response.Headers.Should().ContainKey("x-asset-id").WhoseValue.Should().ContainSingle(id.ToString()); + response.Headers.CacheControl.Public.Should().BeTrue(); + response.Headers.CacheControl.MaxAge.Should().BeGreaterThan(TimeSpan.FromSeconds(2)); + } + [Fact] public async Task Get_V2ManifestForImage_ReturnsManifest_FromMetadata() { diff --git a/src/protagonist/Orchestrator.Tests/Integration/NamedQueryTests.cs b/src/protagonist/Orchestrator.Tests/Integration/NamedQueryTests.cs index 083ae50cb..f2b67b68e 100644 --- a/src/protagonist/Orchestrator.Tests/Integration/NamedQueryTests.cs +++ b/src/protagonist/Orchestrator.Tests/Integration/NamedQueryTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; @@ -195,6 +194,25 @@ public async Task Get_ReturnsV2Manifest_WithCorrectId_IgnoringQueryParam() jsonResponse["@id"].ToString().Should().Be($"http://localhost/{path}"); } + [Fact] + public async Task Get_ReturnsV2Manifest_WithoutImageService3Services() + { + // Arrange + const string path = "iiif-resource/v2/99/test-named-query/my-ref/1"; + const string iiif2 = "application/ld+json; profile=\"http://iiif.io/api/presentation/2/context.json\""; + + // Act + var response = await httpClient.GetAsync($"{path}?foo=bar"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.OK); + response.Headers.Vary.Should().Contain("Accept"); + response.Content.Headers.ContentType.ToString().Should().Be(iiif2); + + var json = await response.Content.ReadAsStringAsync(); + json.Should().NotContain("ImageService3"); + } + [Fact] public async Task Get_ReturnsV3ManifestWithCorrectCount_ViaConneg() { diff --git a/src/protagonist/Orchestrator/Infrastructure/IIIF/IIIFCanvasFactory.cs b/src/protagonist/Orchestrator/Infrastructure/IIIF/IIIFCanvasFactory.cs index c1eed0191..f06c46c73 100644 --- a/src/protagonist/Orchestrator/Infrastructure/IIIF/IIIFCanvasFactory.cs +++ b/src/protagonist/Orchestrator/Infrastructure/IIIF/IIIFCanvasFactory.cs @@ -85,7 +85,7 @@ public IIIFCanvasFactory( Format = "image/jpeg", Width = thumbnailSizes.MaxDerivativeSize.Width, Height = thumbnailSizes.MaxDerivativeSize.Height, - Service = GetImageServices(asset, customerPathElement, authProbeServices) + Service = GetImageServices(asset, customerPathElement, false, authProbeServices) } : null, }.AsListOf() @@ -98,7 +98,7 @@ public IIIFCanvasFactory( { Id = GetFullQualifiedThumbPath(asset, customerPathElement, thumbnailSizes.OpenThumbnails), Format = "image/jpeg", - Service = GetImageServiceForThumbnail(asset, customerPathElement, + Service = GetImageServiceForThumbnail(asset, customerPathElement, false, thumbnailSizes.OpenThumbnails) }.AsListOf(); } @@ -147,7 +147,7 @@ public IIIFCanvasFactory( thumbnailSizes.MaxDerivativeSize, false), Width = thumbnailSizes.MaxDerivativeSize.Width, Height = thumbnailSizes.MaxDerivativeSize.Height, - Service = GetImageServices(asset, customerPathElement, null) + Service = GetImageServices(asset, customerPathElement, true, null) } : null, }.AsList() @@ -158,7 +158,8 @@ public IIIFCanvasFactory( canvas.Thumbnail = new IIIF2.Thumbnail { Id = GetFullQualifiedThumbPath(asset, customerPathElement, thumbnailSizes.OpenThumbnails), - Service = GetImageServiceForThumbnail(asset, customerPathElement, thumbnailSizes.OpenThumbnails) + Service = GetImageServiceForThumbnail(asset, customerPathElement, true, + thumbnailSizes.OpenThumbnails) }.AsList(); } @@ -183,10 +184,10 @@ public IIIFCanvasFactory( }; } - private List GetImageServiceForThumbnail(Asset asset, CustomerPathElement customerPathElement, - List thumbnailSizes) + private List GetImageServiceForThumbnail(Asset asset, CustomerPathElement customerPathElement, + bool forPresentation2, List thumbnailSizes) { - var services = new List(2); + var services = new List(); if (orchestratorSettings.ImageServerConfig.VersionPathTemplates.ContainsKey(ImageApi.Version.V2)) { services.Add(new ImageService2 @@ -198,6 +199,9 @@ private List GetImageServiceForThumbnail(Asset asset, CustomerPathElem }); } + // NOTE - we never include ImageService3 on Presentation2 manifests + if (forPresentation2) return services; + if (orchestratorSettings.ImageServerConfig.VersionPathTemplates.ContainsKey(ImageApi.Version.V3)) { services.Add(new ImageService3 @@ -259,13 +263,14 @@ private string GetFullyQualifiedId(Asset asset, CustomerPathElement customerPath return assetPathGenerator.GetFullPathForRequest(imageRequest, true, false); } - private List GetImageServices(Asset asset, CustomerPathElement customerPathElement, + private List GetImageServices(Asset asset, CustomerPathElement customerPathElement, bool forPresentation2, Dictionary? authProbeServices) { var noAuthServices = authProbeServices.IsNullOrEmpty(); + var versionPathTemplates = orchestratorSettings.ImageServerConfig.VersionPathTemplates; - var services = new List(2); - if (orchestratorSettings.ImageServerConfig.VersionPathTemplates.ContainsKey(ImageApi.Version.V2)) + var services = new List(); + if (versionPathTemplates.ContainsKey(ImageApi.Version.V2)) { services.Add(new ImageService2 { @@ -278,7 +283,10 @@ private List GetImageServices(Asset asset, CustomerPathElement custome }); } - if (orchestratorSettings.ImageServerConfig.VersionPathTemplates.ContainsKey(ImageApi.Version.V3)) + // NOTE - we never include ImageService3 on Presentation2 manifests + if (forPresentation2) return services; + + if (versionPathTemplates.ContainsKey(ImageApi.Version.V3)) { services.Add(new ImageService3 {