diff --git a/src/api/response/iiif/manifest.js b/src/api/response/iiif/manifest.js index 4cd9e96e..816bca5e 100644 --- a/src/api/response/iiif/manifest.js +++ b/src/api/response/iiif/manifest.js @@ -15,6 +15,7 @@ const { function transform(response) { if (response.statusCode === 200) { const builder = new IIIFBuilder(); + const openSearchResponse = JSON.parse(response.body); const source = openSearchResponse._source; @@ -198,10 +199,6 @@ function transform(response) { ]); } - /** Add logo */ - - /** Add provider */ - /** Add items (Canvases) from a Work's Filesets */ source.file_sets .filter((fileSet) => fileSet.role === "Access") @@ -259,6 +256,38 @@ function transform(response) { } } + /** Add logo manually (w/o IIIF Builder) */ + const nulLogo = { + id: "https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp", + type: "Image", + format: "image/webp", + height: 139, + width: 1190, + }; + jsonManifest.logo = [nulLogo]; + + /** Add provider manually (w/o IIIF Builder) */ + const provider = { + id: "https://www.library.northwestern.edu/", + type: "Agent", + label: { none: ["Northwestern University Libraries"] }, + homepage: [ + { + id: "https://dc.library.northwestern.edu/", + type: "Text", + label: { + none: [ + "Northwestern University Libraries Digital Collections Homepage", + ], + }, + format: "text/html", + language: ["en"], + }, + ], + logo: [nulLogo], + }; + jsonManifest.provider = [provider]; + return { statusCode: 200, headers: { diff --git a/src/helpers.js b/src/helpers.js index f5b6f384..6ac00d2c 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -88,7 +88,7 @@ function ensureCharacterEncoding(response, defaultEncoding = "UTF-8") { if (!contentTypeHeader) { contentTypeHeader = "Content-Type"; - response[contentTypeHeader] ||= "application/json; charset=UTF-8"; + response.headers[contentTypeHeader] ||= "application/json; charset=UTF-8"; } const value = parseHeader(response.headers[contentTypeHeader]); diff --git a/test/unit/api/helpers.test.js b/test/unit/api/helpers.test.js index 15bac641..b4009369 100644 --- a/test/unit/api/helpers.test.js +++ b/test/unit/api/helpers.test.js @@ -11,6 +11,7 @@ const { baseUrl, decodeEventBody, decodeToken, + ensureCharacterEncoding, isFromReadingRoom, maybeUseProxiedIp, normalizeHeaders, @@ -403,4 +404,35 @@ describe("helpers", () => { expect(result.queryStringParameters).to.eql({}); }); }); + + describe("ensureCharacterEncoding", () => { + const response = { statusCode: 200, body: "Hello, World!" }; + + it("passes through an existing character set", () => { + const result = ensureCharacterEncoding({ + ...response, + headers: { "Content-Type": "text/plain; charset=ISO-8859-1" }, + }); + expect(result.headers["Content-Type"]).to.eql( + "text/plain; charset=ISO-8859-1" + ); + }); + + it("adds character set if it's missing", () => { + const result = ensureCharacterEncoding({ + ...response, + headers: { "Content-Type": "text/plain" }, + }); + expect(result.headers["Content-Type"]).to.eql( + "text/plain; charset=UTF-8" + ); + }); + + it("adds content type if it's missing", () => { + const result = ensureCharacterEncoding({ ...response, headers: {} }); + expect(result.headers["Content-Type"]).to.eql( + "application/json; charset=UTF-8" + ); + }); + }); }); diff --git a/test/unit/api/response/iiif/manifest.test.js b/test/unit/api/response/iiif/manifest.test.js index 082cc5ff..208a3ac8 100644 --- a/test/unit/api/response/iiif/manifest.test.js +++ b/test/unit/api/response/iiif/manifest.test.js @@ -103,6 +103,36 @@ describe("Image Work as IIIF Manifest response transformer", () => { expect(partOf.summary.none).to.be.an("array").that.is.not.empty; }); + it("populates Manifest logo", async () => { + const { manifest } = await setup(); + const logo = manifest.logo[0]; + expect(logo.id).to.eq( + "https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp" + ); + }); + + it("populates Manifest provider", async () => { + const { manifest } = await setup(); + const provider = manifest.provider[0]; + expect(provider.id).to.eq("https://www.library.northwestern.edu/"); + expect(provider.label).to.deep.equal({ + none: ["Northwestern University Libraries"], + }); + expect(provider.homepage[0].id).to.eq( + "https://dc.library.northwestern.edu/" + ); + expect(provider.homepage[0].label).to.deep.eq({ + none: ["Northwestern University Libraries Digital Collections Homepage"], + }); + expect(provider.logo[0]).to.deep.eq({ + id: "https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp", + type: "Image", + format: "image/webp", + height: 139, + width: 1190, + }); + }); + it("populates Manifest items (canvases)", async () => { const { source, manifest } = await setup(); expect(manifest.items.length).to.eq(3);