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

Using new archive image URLs and manifest URLs but retaining canvas ids. #74

Merged
merged 4 commits into from
May 28, 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
2 changes: 1 addition & 1 deletion iiify/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def manifest(identifier):

@app.route('/iiif/2/<identifier>/manifest.json')
def manifest2(identifier):
domain = "https://iiif.archivelab.org/iiif/"
domain = purify_domain(request.args.get('domain', request.url_root))
page = None
if '$' in identifier:
identifier, page = identifier.split('$')
Expand Down
21 changes: 14 additions & 7 deletions iiify/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import requests
from iiif2 import iiif, web

from .configs import options, cors, approot, cache_root, media_root, apiurl, LINKS
from iiif_prezi3 import Manifest, config, Annotation, AnnotationPage,AnnotationPageRef, Canvas, Manifest, ResourceItem, ServiceItem, Choice, Collection, ManifestRef, CollectionRef

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

return json.loads(collection.jsonld())

def manifest_page(identifier, label='', page='', width='', height='', metadata=None):
def manifest_page(identifier, label='', page='', width='', height='', metadata=None, canvasId=""):
if not canvasId:
canvasId = f"{identifier}/canvas"

metadata = metadata or {}
return {
'@id': '%s/canvas' % identifier,
'@id': canvasId,
'@type': 'sc:Canvas',
'@context': PRZ_CTX,
'description': metadata.get('description', ''),
Expand Down Expand Up @@ -236,7 +240,8 @@ def create_manifest(identifier, domain=None, page=None):
label=metadata['title'],
width=info['width'],
height=info['height'],
metadata=metadata
metadata=metadata,
canvasId= f"https://iiif.archivelab.org/iiif/{identifier}/canvas"
)
)

Expand Down Expand Up @@ -276,7 +281,8 @@ def create_manifest(identifier, domain=None, page=None):
label=metadata['title'],
width=info['width'],
height=info['height'],
metadata=metadata
metadata=metadata,
canvasId= f"https://iiif.archivelab.org/iiif/{identifier}/canvas"
)
)
else:
Expand All @@ -295,7 +301,8 @@ def create_manifest(identifier, domain=None, page=None):
identifier = "%s%s$%s" % (domain, identifier, page),
label=data['pageNums'][page],
width=data['pageWidths'][page],
height=data['pageHeights'][page]
height=data['pageHeights'][page],
canvasId= f"https://iiif.archivelab.org/iiif/{identifier}${page}/canvas"
)
)
return manifest
Expand All @@ -306,7 +313,8 @@ def create_manifest(identifier, domain=None, page=None):
identifier = "%s%s$%s" % (domain, identifier, page),
label=data['pageNums'][page],
width=data['pageWidths'][page],
height=data['pageHeights'][page]
height=data['pageHeights'][page],
canvasId= f"https://iiif.archivelab.org/iiif/{identifier}${page}/canvas"
)
)
return manifest
Expand Down Expand Up @@ -915,7 +923,6 @@ def cantaloupe_resolver(identifier):

#filename = next(f for f in files if f['source'].lower() == 'derivative' \
# and f['name'].endswith('_jp2.zip'))['name']
print("end of logic - filename:", filename)
if filename:
dirpath = filename[:-4]
filepath = f"{fileIdentifier}_{leaf.zfill(4)}{extension}"
Expand Down
37 changes: 36 additions & 1 deletion tests/test_manifests_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,47 @@ def test_v2_image_manifest(self):
self.assertEqual(resp.status_code, 200)
manifest = resp.json

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


def test_v2_image_api(self):
resp = self.test_app.get("/iiif/2/1991-12-compute-magazine/manifest.json")
self.assertEqual(resp.status_code, 200)
manifest = resp.json

self.assertEqual(manifest['@id'], 'https://localhost/iiif/1991-12-compute-magazine/manifest.json', 'V2 Manifest ID is using new infrastructure changed')
image = manifest['sequences'][0]['canvases'][0]['images'][0]['resource']
self.assertEqual(image['@id'], "https://localhost/iiif/1991-12-compute-magazine$0/full/full/0/default.jpg", "Resource not using new image server")
self.assertEqual(image['service']['@id'], 'https://localhost/iiif/1991-12-compute-magazine$0', "V2 service not using the new image server")

def test_v2_single_image(self):
resp = self.test_app.get("/iiif/2/img-8664_202009/manifest.json")
self.assertEqual(resp.status_code, 200)
manifest = resp.json

self.assertEqual(manifest['@id'], 'https://localhost/iiif/img-8664_202009/manifest.json', 'V2 Manifest ID is using new infrastructure changed')
canvas = manifest['sequences'][0]['canvases'][0]
self.assertEqual(canvas['@id'], 'https://iiif.archivelab.org/iiif/img-8664_202009/canvas', 'Expected canvas id to be the same')
image = canvas['images'][0]['resource']
self.assertEqual(image['@id'], "https://localhost/iiif/img-8664_202009/full/full/0/default.jpg", "Resource not using new image server")
self.assertEqual(image['service']['@id'], 'https://localhost/iiif/img-8664_202009', "V2 service not using the new image server")

def test_v2_single_text_manifest(self):
resp = self.test_app.get("/iiif/2/fbf_3chords_1_/manifest.json")
self.assertEqual(resp.status_code, 200)
manifest = resp.json

self.assertEqual(manifest['@id'], 'https://localhost/iiif/fbf_3chords_1_/manifest.json', 'V2 Manifest ID is using new infrastructure changed')
canvas = manifest['sequences'][0]['canvases'][0]
self.assertEqual(canvas['@id'], 'https://iiif.archivelab.org/iiif/fbf_3chords_1_$0/canvas', 'Expected canvas id to be the same')
image = canvas['images'][0]['resource']
self.assertEqual(image['@id'], "https://localhost/iiif/fbf_3chords_1_$0/full/full/0/default.jpg", "Resource not using new image server")
self.assertEqual(image['service']['@id'], 'https://localhost/iiif/fbf_3chords_1_$0', "V2 service not using the new image server")


def test_text_which_is_image(self):
resp = self.test_app.get("/iiif/2/fbf_3chords_1_/manifest.json")

Expand Down
Loading