Skip to content

Commit fd9f88a

Browse files
authored
Merge pull request #74 from internetarchive/issue-26
Using new archive image URLs and manifest URLs but retaining canvas ids.
2 parents 8198705 + bb828a6 commit fd9f88a

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

iiify/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def manifest(identifier):
204204

205205
@app.route('/iiif/2/<identifier>/manifest.json')
206206
def manifest2(identifier):
207-
domain = "https://iiif.archivelab.org/iiif/"
207+
domain = purify_domain(request.args.get('domain', request.url_root))
208208
page = None
209209
if '$' in identifier:
210210
identifier, page = identifier.split('$')

iiify/resolver.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import requests
55
from iiif2 import iiif, web
6+
67
from .configs import options, cors, approot, cache_root, media_root, apiurl, LINKS
78
from iiif_prezi3 import Manifest, config, Annotation, AnnotationPage,AnnotationPageRef, Canvas, Manifest, ResourceItem, ServiceItem, Choice, Collection, ManifestRef, CollectionRef
89

@@ -147,10 +148,13 @@ def create_collection3(identifier, domain, page=1, rows=1000):
147148

148149
return json.loads(collection.jsonld())
149150

150-
def manifest_page(identifier, label='', page='', width='', height='', metadata=None):
151+
def manifest_page(identifier, label='', page='', width='', height='', metadata=None, canvasId=""):
152+
if not canvasId:
153+
canvasId = f"{identifier}/canvas"
154+
151155
metadata = metadata or {}
152156
return {
153-
'@id': '%s/canvas' % identifier,
157+
'@id': canvasId,
154158
'@type': 'sc:Canvas',
155159
'@context': PRZ_CTX,
156160
'description': metadata.get('description', ''),
@@ -236,7 +240,8 @@ def create_manifest(identifier, domain=None, page=None):
236240
label=metadata['title'],
237241
width=info['width'],
238242
height=info['height'],
239-
metadata=metadata
243+
metadata=metadata,
244+
canvasId= f"https://iiif.archivelab.org/iiif/{identifier}/canvas"
240245
)
241246
)
242247

@@ -276,7 +281,8 @@ def create_manifest(identifier, domain=None, page=None):
276281
label=metadata['title'],
277282
width=info['width'],
278283
height=info['height'],
279-
metadata=metadata
284+
metadata=metadata,
285+
canvasId= f"https://iiif.archivelab.org/iiif/{identifier}/canvas"
280286
)
281287
)
282288
else:
@@ -295,7 +301,8 @@ def create_manifest(identifier, domain=None, page=None):
295301
identifier = "%s%s$%s" % (domain, identifier, page),
296302
label=data['pageNums'][page],
297303
width=data['pageWidths'][page],
298-
height=data['pageHeights'][page]
304+
height=data['pageHeights'][page],
305+
canvasId= f"https://iiif.archivelab.org/iiif/{identifier}${page}/canvas"
299306
)
300307
)
301308
return manifest
@@ -306,7 +313,8 @@ def create_manifest(identifier, domain=None, page=None):
306313
identifier = "%s%s$%s" % (domain, identifier, page),
307314
label=data['pageNums'][page],
308315
width=data['pageWidths'][page],
309-
height=data['pageHeights'][page]
316+
height=data['pageHeights'][page],
317+
canvasId= f"https://iiif.archivelab.org/iiif/{identifier}${page}/canvas"
310318
)
311319
)
312320
return manifest
@@ -915,7 +923,6 @@ def cantaloupe_resolver(identifier):
915923

916924
#filename = next(f for f in files if f['source'].lower() == 'derivative' \
917925
# and f['name'].endswith('_jp2.zip'))['name']
918-
print("end of logic - filename:", filename)
919926
if filename:
920927
dirpath = filename[:-4]
921928
filepath = f"{fileIdentifier}_{leaf.zfill(4)}{extension}"

tests/test_manifests_v2.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,47 @@ def test_v2_image_manifest(self):
1515
self.assertEqual(resp.status_code, 200)
1616
manifest = resp.json
1717

18-
self.assertEqual(manifest['@id'], 'https://iiif.archivelab.org/iiif/rashodgson68/manifest.json', 'V2 Manifest ID has changed')
18+
self.assertEqual(manifest['@id'], 'https://localhost/iiif/rashodgson68/manifest.json', 'V2 Manifest ID is using new infrastructure changed')
1919
self.assertEqual(manifest['@type'], "sc:Manifest", f"Unexpected type. Expected Manifest got {manifest['@type']}")
2020
self.assertEqual(len(manifest['sequences'][0]['canvases']),32,f"Expected 32 canvases but got: {len(manifest['sequences'][0]['canvases'])}")
2121
self.assertEqual(manifest['sequences'][0]['canvases'][0]['@id'],"https://iiif.archivelab.org/iiif/rashodgson68$0/canvas",f"v2 canvas id has changed")
2222

2323

24+
def test_v2_image_api(self):
25+
resp = self.test_app.get("/iiif/2/1991-12-compute-magazine/manifest.json")
26+
self.assertEqual(resp.status_code, 200)
27+
manifest = resp.json
28+
29+
self.assertEqual(manifest['@id'], 'https://localhost/iiif/1991-12-compute-magazine/manifest.json', 'V2 Manifest ID is using new infrastructure changed')
30+
image = manifest['sequences'][0]['canvases'][0]['images'][0]['resource']
31+
self.assertEqual(image['@id'], "https://localhost/iiif/1991-12-compute-magazine$0/full/full/0/default.jpg", "Resource not using new image server")
32+
self.assertEqual(image['service']['@id'], 'https://localhost/iiif/1991-12-compute-magazine$0', "V2 service not using the new image server")
33+
34+
def test_v2_single_image(self):
35+
resp = self.test_app.get("/iiif/2/img-8664_202009/manifest.json")
36+
self.assertEqual(resp.status_code, 200)
37+
manifest = resp.json
38+
39+
self.assertEqual(manifest['@id'], 'https://localhost/iiif/img-8664_202009/manifest.json', 'V2 Manifest ID is using new infrastructure changed')
40+
canvas = manifest['sequences'][0]['canvases'][0]
41+
self.assertEqual(canvas['@id'], 'https://iiif.archivelab.org/iiif/img-8664_202009/canvas', 'Expected canvas id to be the same')
42+
image = canvas['images'][0]['resource']
43+
self.assertEqual(image['@id'], "https://localhost/iiif/img-8664_202009/full/full/0/default.jpg", "Resource not using new image server")
44+
self.assertEqual(image['service']['@id'], 'https://localhost/iiif/img-8664_202009', "V2 service not using the new image server")
45+
46+
def test_v2_single_text_manifest(self):
47+
resp = self.test_app.get("/iiif/2/fbf_3chords_1_/manifest.json")
48+
self.assertEqual(resp.status_code, 200)
49+
manifest = resp.json
50+
51+
self.assertEqual(manifest['@id'], 'https://localhost/iiif/fbf_3chords_1_/manifest.json', 'V2 Manifest ID is using new infrastructure changed')
52+
canvas = manifest['sequences'][0]['canvases'][0]
53+
self.assertEqual(canvas['@id'], 'https://iiif.archivelab.org/iiif/fbf_3chords_1_$0/canvas', 'Expected canvas id to be the same')
54+
image = canvas['images'][0]['resource']
55+
self.assertEqual(image['@id'], "https://localhost/iiif/fbf_3chords_1_$0/full/full/0/default.jpg", "Resource not using new image server")
56+
self.assertEqual(image['service']['@id'], 'https://localhost/iiif/fbf_3chords_1_$0', "V2 service not using the new image server")
57+
58+
2459
def test_text_which_is_image(self):
2560
resp = self.test_app.get("/iiif/2/fbf_3chords_1_/manifest.json")
2661

0 commit comments

Comments
 (0)