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

Do not include ImageService3 on v2 manifests #867

Merged
merged 1 commit into from
Jun 24, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class 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<IAnnotation>()
Expand All @@ -98,7 +98,7 @@ public class IIIFCanvasFactory
{
Id = GetFullQualifiedThumbPath(asset, customerPathElement, thumbnailSizes.OpenThumbnails),
Format = "image/jpeg",
Service = GetImageServiceForThumbnail(asset, customerPathElement,
Service = GetImageServiceForThumbnail(asset, customerPathElement, false,
thumbnailSizes.OpenThumbnails)
}.AsListOf<ExternalResource>();
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public class 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()
Expand All @@ -158,7 +158,8 @@ public class 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();
}

Expand All @@ -183,10 +184,10 @@ public class IIIFCanvasFactory
};
}

private List<IService> GetImageServiceForThumbnail(Asset asset, CustomerPathElement customerPathElement,
List<Size> thumbnailSizes)
private List<IService> GetImageServiceForThumbnail(Asset asset, CustomerPathElement customerPathElement,
bool forPresentation2, List<Size> thumbnailSizes)
{
var services = new List<IService>(2);
var services = new List<IService>();
if (orchestratorSettings.ImageServerConfig.VersionPathTemplates.ContainsKey(ImageApi.Version.V2))
{
services.Add(new ImageService2
Expand All @@ -198,6 +199,9 @@ public class IIIFCanvasFactory
});
}

// NOTE - we never include ImageService3 on Presentation2 manifests
if (forPresentation2) return services;

if (orchestratorSettings.ImageServerConfig.VersionPathTemplates.ContainsKey(ImageApi.Version.V3))
{
services.Add(new ImageService3
Expand Down Expand Up @@ -259,13 +263,14 @@ public class IIIFCanvasFactory
return assetPathGenerator.GetFullPathForRequest(imageRequest, true, false);
}

private List<IService> GetImageServices(Asset asset, CustomerPathElement customerPathElement,
private List<IService> GetImageServices(Asset asset, CustomerPathElement customerPathElement, bool forPresentation2,
Dictionary<AssetId, AuthProbeService2>? authProbeServices)
{
var noAuthServices = authProbeServices.IsNullOrEmpty();
var versionPathTemplates = orchestratorSettings.ImageServerConfig.VersionPathTemplates;

var services = new List<IService>(2);
if (orchestratorSettings.ImageServerConfig.VersionPathTemplates.ContainsKey(ImageApi.Version.V2))
var services = new List<IService>();
if (versionPathTemplates.ContainsKey(ImageApi.Version.V2))
{
services.Add(new ImageService2
{
Expand All @@ -278,7 +283,10 @@ public class IIIFCanvasFactory
});
}

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
{
Expand Down
Loading