Skip to content

Commit 3131036

Browse files
authored
Merge pull request #149 from nulib/4010-placeholder-canvas-defensiveness
Add defensiveness for placeholderCanvas if fileset width OR height are null.
2 parents e279deb + 1d9ace9 commit 3131036

File tree

5 files changed

+385
-15
lines changed

5 files changed

+385
-15
lines changed

src/api/response/iiif/manifest.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,14 @@ function transform(response) {
248248
(fileSet) =>
249249
fileSet.representative_image_url === thumbnail[0].service[0]["@id"]
250250
);
251-
jsonManifest.items[i].placeholderCanvas = buildPlaceholderCanvas(
252-
id,
253-
placeholderFileSet
254-
);
251+
252+
// only add the placeholderCanvas property if the fileSet has width and height
253+
if (placeholderFileSet.width && placeholderFileSet.height) {
254+
jsonManifest.items[i].placeholderCanvas = buildPlaceholderCanvas(
255+
id,
256+
placeholderFileSet
257+
);
258+
}
255259
}
256260
}
257261

src/api/response/iiif/presentation-api/placeholder-canvas.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ function buildPlaceholderCanvas(id, fileSet, size = 640) {
4242
}
4343

4444
function getPlaceholderSizes(fileset, size) {
45-
const { width, height } = fileset;
45+
const width = fileset?.width ?? 100;
46+
const height = fileset?.height ?? 100;
4647
const placeholderWidth = width > size ? size : width;
4748
const placeholderHeight = Math.floor((placeholderWidth / width) * height);
4849
return { placeholderWidth, placeholderHeight };
Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
{
2+
"_index": "dev-dc-v2-work",
3+
"_type": "_doc",
4+
"_id": "1234",
5+
"_version": 1,
6+
"_seq_no": 719,
7+
"_primary_term": 1,
8+
"found": true,
9+
"_source": {
10+
"provenance": [
11+
"Artist; sold to Mr. Blank in 1955; sold to Lancelot in 2017; gifted to Northwestern University in 2019"
12+
],
13+
"contributor": [
14+
{
15+
"facet": "http://id.loc.gov/authorities/names/n91114928|ctg|Metallica (Musical group) (Cartographer)",
16+
"id": "http://id.loc.gov/authorities/names/n91114928",
17+
"label": "Metallica (Musical group)",
18+
"label_with_role": "Metallica (Musical group) (Cartographer)",
19+
"role": "Cartographer",
20+
"variants": []
21+
},
22+
{
23+
"facet": "http://id.worldcat.org/fast/1204616|abr|South Africa (Abridger)",
24+
"id": "http://id.worldcat.org/fast/1204616",
25+
"label": "South Africa",
26+
"label_with_role": "South Africa (Abridger)",
27+
"role": "Abridger",
28+
"variants": []
29+
},
30+
{
31+
"facet": "http://id.worldcat.org/fast/1150166|app|Thistles (Applicant)",
32+
"id": "http://id.worldcat.org/fast/1150166",
33+
"label": "Thistles",
34+
"label_with_role": "Thistles (Applicant)",
35+
"role": "Applicant",
36+
"variants": []
37+
}
38+
],
39+
"batch_ids": [
40+
"a846a5f2-da57-49e6-a138-f5462d113a55",
41+
"97aac3e3-389a-47ac-a7b3-5dd6ffffd558",
42+
"e2529123-6a8c-4f6d-89d5-0257a1b947d4",
43+
"b3d3462d-c03e-4cae-9219-4e38335a25fc",
44+
"1591cc1e-009d-4b39-97a2-7d8743fb957b",
45+
"80a15dc2-92d5-48a4-9aa4-73ecdcb1d130"
46+
],
47+
"publisher": ["Northwestern University Press"],
48+
"subject": [
49+
{
50+
"facet": "http://id.worldcat.org/fast/1902713|TOPICAL|Cats on postage stamps (Topical)",
51+
"id": "http://id.worldcat.org/fast/1902713",
52+
"label": "Cats on postage stamps",
53+
"label_with_role": "Cats on postage stamps (Topical)",
54+
"role": "Topical",
55+
"variants": []
56+
},
57+
{
58+
"facet": "info:nul/6cba23b5-a91a-4c13-8398-54967b329d48|TOPICAL|Test Record Canary (Topical)",
59+
"id": "info:nul/6cba23b5-a91a-4c13-8398-54967b329d48",
60+
"label": "Test Record Canary",
61+
"label_with_role": "Test Record Canary (Topical)",
62+
"role": "Topical",
63+
"variants": []
64+
},
65+
{
66+
"facet": "http://vocab.getty.edu/tgn/2000971|GEOGRAPHICAL|Leelanau (Geographical)",
67+
"id": "http://vocab.getty.edu/tgn/2000971",
68+
"label": "Leelanau",
69+
"label_with_role": "Leelanau (Geographical)",
70+
"role": "Geographical",
71+
"variants": []
72+
},
73+
{
74+
"facet": "http://id.worldcat.org/fast/1204587|GEOGRAPHICAL|Michigan--Ann Arbor (Geographical)",
75+
"id": "http://id.worldcat.org/fast/1204587",
76+
"label": "Michigan--Ann Arbor",
77+
"label_with_role": "Michigan--Ann Arbor (Geographical)",
78+
"role": "Geographical",
79+
"variants": []
80+
}
81+
],
82+
"scope_and_contents": ["I promise there is scope and content"],
83+
"notes": [
84+
{
85+
"note": "Here are some notes",
86+
"type": "General Note"
87+
},
88+
{
89+
"note": "Awards type",
90+
"type": "Awards"
91+
},
92+
{
93+
"note": "Biographical note",
94+
"type": "Biographical/Historical Note"
95+
},
96+
{
97+
"note": "creation production credits",
98+
"type": "Creation/Production Credits"
99+
},
100+
{
101+
"note": "Language note",
102+
"type": "Language Note"
103+
},
104+
{
105+
"note": "Local Note",
106+
"type": "Local Note"
107+
},
108+
{
109+
"note": "Performers",
110+
"type": "Performers"
111+
},
112+
{
113+
"note": "Statement of Responsibility",
114+
"type": "Statement of Responsibility"
115+
},
116+
{
117+
"note": "Venue/event date",
118+
"type": "Venue/Event Date"
119+
},
120+
{
121+
"note": "massive add to all pages/check",
122+
"type": "General Note"
123+
}
124+
],
125+
"related_material": ["See Also: related material"],
126+
"accession_number": "Canary_002",
127+
"modified_date": "2022-10-13T20:56:31.249155Z",
128+
"folder_names": ["Blue folder"],
129+
"series": ["Canaries and How to Care for Them"],
130+
"cultural_context": ["Test Context"],
131+
"language": [
132+
{
133+
"facet": "http://id.loc.gov/vocabulary/languages/crh||Crimean Tatar",
134+
"id": "http://id.loc.gov/vocabulary/languages/crh",
135+
"label": "Crimean Tatar",
136+
"variants": []
137+
}
138+
],
139+
"location": [
140+
{
141+
"facet": "https://sws.geonames.org/4999069/||Leland Township",
142+
"id": "https://sws.geonames.org/4999069/",
143+
"label": "Leland Township",
144+
"variants": []
145+
}
146+
],
147+
"create_date": "2022-03-02T20:38:29.813494Z",
148+
"thumbnail": "https://index.test.library.northwestern.edu/iiif/2/mbk-dev/5678/square/!300,300/0/default.jpg",
149+
"id": "1234",
150+
"collection": {
151+
"id": "7c50096c-89eb-43e8-b357-5836a788ddeb",
152+
"title": "TEST Canary Records",
153+
"description": "This is the description of the collection"
154+
},
155+
"abstract": [],
156+
"creator": [
157+
{
158+
"facet": "http://id.loc.gov/authorities/names/no2011059409||Dessa (Vocalist)",
159+
"id": "http://id.loc.gov/authorities/names/no2011059409",
160+
"label": "Dessa (Vocalist)",
161+
"variants": [
162+
"Dessa, 1981-",
163+
"Wander, Dessa, 1981-",
164+
"Dessa Darling",
165+
"Wander, Margret"
166+
]
167+
},
168+
{
169+
"facet": "http://id.worldcat.org/fast/1152763||Tornadoes",
170+
"id": "http://id.worldcat.org/fast/1152763",
171+
"label": "Tornadoes",
172+
"variants": []
173+
},
174+
{
175+
"facet": "http://vocab.getty.edu/aat/300443944||photo editors",
176+
"id": "http://vocab.getty.edu/aat/300443944",
177+
"label": "photo editors",
178+
"variants": []
179+
},
180+
{
181+
"facet": "http://id.worldcat.org/fast/1717972||Schober, Franz von, 1796-1882",
182+
"id": "http://id.worldcat.org/fast/1717972",
183+
"label": "Schober, Franz von, 1796-1882",
184+
"variants": []
185+
}
186+
],
187+
"rights_holder": ["Artist"],
188+
"box_number": ["88"],
189+
"physical_description_size": ["16 x 24 inches"],
190+
"description": [
191+
"This is a private record for RepoDev testing on production"
192+
],
193+
"keywords": ["leaves"],
194+
"indexed_at": "2022-10-14T14:19:42.844994",
195+
"folder_numbers": ["88"],
196+
"genre": [
197+
{
198+
"facet": "http://id.worldcat.org/fast/1919896||Biographies",
199+
"id": "http://id.worldcat.org/fast/1919896",
200+
"label": "Biographies",
201+
"variants": []
202+
},
203+
{
204+
"facet": "http://id.worldcat.org/fast/1019337||Mice",
205+
"id": "http://id.worldcat.org/fast/1019337",
206+
"label": "Mice",
207+
"variants": []
208+
}
209+
],
210+
"date_created": ["August 1906 to December 1910", "1958"],
211+
"title": "Canary Record TEST 1",
212+
"physical_description_material": ["Acrylic paint on cement block"],
213+
"csv_metadata_update_jobs": [
214+
"5753101a-42fa-4838-9b71-f1594a5b1d5f",
215+
"6b46db60-6f6a-45e8-8b8d-ab0029a1e8fe",
216+
"38988b3e-5778-41da-85a5-e16d13cb098a",
217+
"21838181-8d12-4015-8b98-0874061adb98"
218+
],
219+
"ark": "ark:/99999/fk47h32p0m",
220+
"caption": ["Beebo"],
221+
"status": "Done",
222+
"style_period": [
223+
{
224+
"facet": "http://vocab.getty.edu/aat/300018478||Qing (dynastic styles and periods)",
225+
"id": "http://vocab.getty.edu/aat/300018478",
226+
"label": "Qing (dynastic styles and periods)",
227+
"variants": []
228+
}
229+
],
230+
"api_model": "Work",
231+
"catalog_key": ["MS-1984-1982-1989"],
232+
"rights_statement": {
233+
"id": "http://rightsstatements.org/vocab/InC-EDU/1.0/",
234+
"label": "In Copyright - Educational Use Permitted"
235+
},
236+
"file_sets": [
237+
{
238+
"duration": null,
239+
"height": null,
240+
"id": "076dcbd8-8c57-40e8-bdf7-dc9153c87a36",
241+
"label": "Access File - Tiff",
242+
"mime_type": "image/tiff",
243+
"original_filename": "Squirrel.tif",
244+
"poster_offset": null,
245+
"rank": 0,
246+
"representative_image_url": "https://iiif.stack.rdc-staging.library.northwestern.edu/iiif/2/076dcbd8-8c57-40e8-bdf7-dc9153c87a36",
247+
"role": "Access",
248+
"streaming_url": null,
249+
"webvtt": null,
250+
"width": null
251+
}
252+
],
253+
"library_unit": "Charles Deering McCormick Library of Special Collections",
254+
"technique": [
255+
{
256+
"facet": "http://vocab.getty.edu/aat/300053228||drypoint (printing process)",
257+
"id": "http://vocab.getty.edu/aat/300053228",
258+
"label": "drypoint (printing process)",
259+
"variants": []
260+
}
261+
],
262+
"table_of_contents": ["1. cats; 2. dogs"],
263+
"representative_file_set": {
264+
"fileSetId": "5678",
265+
"url": "https://index.test.library.northwestern.edu/iiif/2/mbk-dev/5678"
266+
},
267+
"related_url": [
268+
{
269+
"label": "Finding Aid",
270+
"url": "https://findingaids.library.northwestern.edu/"
271+
},
272+
{
273+
"label": "Research Guide",
274+
"url": "https://www.wbez.org/"
275+
},
276+
{
277+
"label": "Related Information",
278+
"url": "https://www.nationalgeographic.com/animals/mammals/facts/squirrels"
279+
},
280+
{
281+
"label": "Hathi Trust Digital Library",
282+
"url": "https://www.hathitrust.org/"
283+
}
284+
],
285+
"terms_of_use": "Terms ",
286+
"visibility": "Public",
287+
"license": {
288+
"id": "http://www.europeana.eu/portal/rights/rr-r.html",
289+
"label": "All rights reserved",
290+
"scheme": "license"
291+
},
292+
"api_link": "https://dcapi.rdc-staging.library.northwestern.edu/api/v2/works/1234",
293+
"alternate_title": ["This is an alternative title"],
294+
"preservation_level": "Level 1",
295+
"published": true,
296+
"source": ["Mars"],
297+
"iiif_manifest": "https://iiif.stack.rdc-staging.library.northwestern.edu/public/15/6a/8f/8e/-5/49/b-/49/82/-8/6c/c-/37/5b/f0/41/04/ff-manifest.json",
298+
"legacy_identifier": ["555"],
299+
"work_type": "Image",
300+
"identifier": ["555"],
301+
"box_name": ["The name of a box"]
302+
}
303+
}

test/unit/api/response/iiif/manifest.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,41 @@ describe("Image Work as IIIF Manifest response transformer", () => {
167167
});
168168
});
169169

170+
describe("Image Work with fileset missing width and height as IIIF Manifest response transformer", () => {
171+
async function setup() {
172+
const response = {
173+
statusCode: 200,
174+
body: helpers.testFixture("mocks/work-1234-no-fileset-width-height.json"),
175+
};
176+
const source = JSON.parse(response.body)._source;
177+
178+
const result = await transformer.transform(response);
179+
expect(result.statusCode).to.eq(200);
180+
181+
return { source, manifest: JSON.parse(result.body) };
182+
}
183+
184+
it("sets canvas width and height to a default value", async () => {
185+
const { manifest } = await setup();
186+
const { width, height } = manifest.items[0];
187+
expect(width).to.eq(100);
188+
expect(height).to.eq(100);
189+
});
190+
191+
it("sets canvas annotation body width and height to a default value", async () => {
192+
const { manifest } = await setup();
193+
const { width, height } = manifest.items[0].items[0].items[0].body;
194+
expect(width).to.eq(100);
195+
expect(height).to.eq(100);
196+
});
197+
198+
it("excludes placeholderCanvas property on Image canvases if filset does not have width OR height", async () => {
199+
const { manifest } = await setup();
200+
const { placeholderCanvas } = manifest.items[0];
201+
expect(placeholderCanvas).to.eq(undefined);
202+
});
203+
});
204+
170205
describe("A/V Work as IIIF Manifest response transformer", () => {
171206
async function setup() {
172207
const response = {

0 commit comments

Comments
 (0)