Skip to content

Commit

Permalink
Tackling #46 returning empty canvas if image request failed
Browse files Browse the repository at this point in the history
  • Loading branch information
glenrobson committed Feb 9, 2024
1 parent b49e6e3 commit 28423ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 12 additions & 2 deletions iiify/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def checkMultiItem(metadata):
file_types[file['format']] = 0

file_types[file['format']] += 1
print (file_types)

# If there is multiple files of the same type then return the first format
# Will have to see if there are objects with multiple images and formats
Expand Down Expand Up @@ -472,18 +473,27 @@ def create_manifest3(identifier, domain=None, page=None):
elif mediatype == 'image':
(multiFile, format) = checkMultiItem(metadata)
print (f"Checking multiFile {multiFile} {format}")
# st-anthony-relics-01%2fAuronzo-ComuneCortina.jpeg
# st-anthony-relics-01%2FStAnthony-Relics_01.jpeg
if multiFile:
# Create multi file manifest
for file in metadata['files']:
if file['source'] == "original" and file['format'] == format:
imgId = f"{identifier}/{file['name']}".replace('/','%2f')
imgURL = f"{IMG_SRV}/3/{imgId}"

manifest.make_canvas_from_iiif(url=imgURL,
try:
manifest.make_canvas_from_iiif(url=imgURL,
id=f"{URI_PRIFIX}/{identifier}/canvas",
label="1",
label=f"{file['name']}",
anno_page_id=f"{uri}/annotationPage/1",
anno_id=f"{uri}/annotation/1")
except requests.exceptions.HTTPError as error:
print (f'Failed to get {imgURL}')
manifest.make_canvas(label=f"Failed to load {file['name']} from Image Server",
summary=f"Got {error}",
id=f"{URI_PRIFIX}/{identifier}/canvas",
height=1800, width=1200)
else:
singleImage(metadata, identifier, manifest, uri)
elif mediatype == 'audio' or mediatype == 'etree':
Expand Down
5 changes: 5 additions & 0 deletions tests/test_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ def test_multi_file(self):
manifest = resp.json
self.assertEqual(len(manifest['items']),3, f"Expected three canvases, but got {len(manifest['items'])}")

def test_multi_file(self):
resp = self.test_app.get("/iiif/3/st-anthony-relics-01/manifest.json")
self.assertEqual(resp.status_code, 200)
manifest = resp.json
self.assertEqual(len(manifest['items']),5, f"Expected five canvases, but got {len(manifest['items'])}")


''' to test:
Expand Down

0 comments on commit 28423ce

Please sign in to comment.