From 5107ecfa8cefb10316c0d2ba9b1e9879a64e56e9 Mon Sep 17 00:00:00 2001 From: BernhardKoschicek Date: Wed, 4 Oct 2023 17:41:32 +0200 Subject: [PATCH] added thumbnail to manifest --- openatlas/api/endpoints/iiif.py | 30 +++++++++++++++++++++++------- openatlas/api/routes.py | 6 +++--- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/openatlas/api/endpoints/iiif.py b/openatlas/api/endpoints/iiif.py index a98ce6efc..000ecb3c9 100644 --- a/openatlas/api/endpoints/iiif.py +++ b/openatlas/api/endpoints/iiif.py @@ -12,7 +12,7 @@ class IIIFSequence(Resource): @staticmethod - def get(id_: int) -> Response: + def get(version: int, id_: int) -> Response: img_url = f"{app.config['IIIF']['url']}{id_}" req = requests.get(f"{img_url}/info.json") img_api = req.json() @@ -27,6 +27,7 @@ def build_sequence(entity: Entity, img_url: str, img_api: dict[str, Any]): "@id": url_for( 'api.iiif_sequence', id_=entity.id, + version=2, _external=True), "@type": "sc:Sequence", "label": [{ @@ -38,7 +39,7 @@ def build_sequence(entity: Entity, img_url: str, img_api: dict[str, Any]): class IIIFCanvas(Resource): @staticmethod - def get(id_: int) -> Response: + def get(version: int, id_: int) -> Response: img_url = f"{app.config['IIIF']['url']}{id_}" req = requests.get(f"{img_url}/info.json") img_api = req.json() @@ -50,7 +51,8 @@ def get(id_: int) -> Response: @staticmethod def build_canvas(entity: Entity, img_url: str, img_api: dict[str, Any]): return { - "@id": url_for('api.iiif_canvas', id_=entity.id, _external=True), + "@id": url_for( + 'api.iiif_canvas', id_=entity.id, version=2, _external=True), "@type": "sc:Canvas", "label": entity.name, "height": img_api['height'], @@ -60,12 +62,24 @@ def build_canvas(entity: Entity, img_url: str, img_api: dict[str, Any]): "@language": "en"}, "images": [ IIIFImage.build_image(entity.id, img_url, img_api)], - "related": ""} + "related": "", + "thumbnail": { + "@id": f'{img_url}/full/!200,200/0/default.jpg', + "@type": "dctypes:Image", + "format": "image/jpeg", + "height": 200, + "width": 200, + "service": { + "@context": "http://iiif.io/api/image/2/context.json", + "@id": img_url, + "profile": img_api['profile']}, + }, + } class IIIFImage(Resource): @staticmethod - def get(id_: int) -> Response: + def get(version: int, id_: int) -> Response: image_url = f"{app.config['IIIF']['url']}{id_}" req = requests.get(f"{image_url}/info.json") image_api = req.json() @@ -75,7 +89,8 @@ def get(id_: int) -> Response: def build_image(id_: int, img_url: str, img_api: dict[str, Any]): return { "@context": "https://iiif.io/api/presentation/2/context.json", - "@id": url_for('api.iiif_image', id_=id_, _external=True), + "@id": + url_for('api.iiif_image', id_=id_, version=2, _external=True), "@type": "oa:Annotation", "motivation": "sc:painting", "resource": { @@ -88,7 +103,8 @@ def build_image(id_: int, img_url: str, img_api: dict[str, Any]): "profile": img_api['profile']}, "height": img_api['height'], "width": img_api['width']}, - "on": url_for('api.iiif_canvas', id_=id_, _external=True)} + "on": + url_for('api.iiif_canvas', id_=id_, version=2, _external=True)} class IIIFManifest(Resource): diff --git a/openatlas/api/routes.py b/openatlas/api/routes.py index bee91cf82..a2834ca86 100644 --- a/openatlas/api/routes.py +++ b/openatlas/api/routes.py @@ -107,13 +107,13 @@ def add_routes_v03(api: Api) -> None: endpoint='iiif_manifest') api.add_resource( IIIFImage, - '/iiif_image/.json', + '/iiif_image//.json', endpoint='iiif_image') api.add_resource( IIIFCanvas, - '/iiif_canvas/.json', + '/iiif_canvas//.json', endpoint='iiif_canvas') api.add_resource( IIIFSequence, - '/iiif_sequence/.json', + '/iiif_sequence//.json', endpoint='iiif_sequence')