forked from craws/OpenAtlas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature_docker_k8s
- Loading branch information
Showing
26 changed files
with
548 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Create a directory for the iipsrv binary | ||
ScriptAlias /iiif "/var/www/iipsrv/iipsrv.fcgi" | ||
|
||
# Set the options on that directory | ||
<Location "iipsrv/"> | ||
AllowOverride None | ||
Options None | ||
<IfModule mod_version.c> | ||
<IfVersion < 2.4> | ||
Order allow,deny | ||
Allow from all | ||
</IfVersion> | ||
<IfVersion >= 2.4> | ||
Require all granted | ||
</IfVersion> | ||
</IfModule> | ||
# Set the module handler | ||
AddHandler fcgid-script .fcgi | ||
</Location> | ||
|
||
# Set our environment variables for the IIP server | ||
FcgidInitialEnv VERBOSITY "6" | ||
FcgidInitialEnv LOGFILE "/var/log/iipsrv.log" | ||
FcgidInitialEnv MAX_IMAGE_CACHE_SIZE "10" | ||
FcgidInitialEnv JPEG_QUALITY "90" | ||
FcgidInitialEnv MAX_CVT "5000" | ||
FcgidInitialEnv MEMCACHED_SERVERS "localhost" | ||
FcgidInitialEnv CORS "*" | ||
FcgidInitialEnv URI_MAP "iiif=>IIIF" | ||
|
||
# Define the idle timeout as unlimited and the number of | ||
# processes we want | ||
FcgidIdleTimeout 0 | ||
FcgidMaxProcessesPerClass 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
from typing import Any | ||
|
||
import requests | ||
from flask import jsonify, Response, url_for, g | ||
from flask_restful import Resource | ||
|
||
from openatlas import app | ||
from openatlas.api.resources.model_mapper import get_entity_by_id | ||
from openatlas.api.resources.util import get_license_name | ||
from openatlas.models.entity import Entity | ||
|
||
|
||
class IIIFSequenceV2(Resource): | ||
@staticmethod | ||
def get(id_: int) -> Response: | ||
return jsonify( | ||
{"@context": "https://iiif.io/api/presentation/2/context.json"} | | ||
IIIFSequenceV2.build_sequence(get_metadata(get_entity_by_id(id_)))) | ||
|
||
@staticmethod | ||
def build_sequence(metadata: dict[str, Any]) -> dict[str, Any]: | ||
return { | ||
"@id": url_for( | ||
'api.iiif_sequence', | ||
id_=metadata['entity'].id, | ||
version=2, | ||
_external=True), | ||
"@type": "sc:Sequence", | ||
"label": [{ | ||
"@value": "Normal Sequence", | ||
"@language": "en"}], | ||
"canvases": [ | ||
IIIFCanvasV2.build_canvas(metadata)]} | ||
|
||
|
||
class IIIFCanvasV2(Resource): | ||
@staticmethod | ||
def get(id_: int) -> Response: | ||
return jsonify( | ||
{"@context": "https://iiif.io/api/presentation/2/context.json"} | | ||
IIIFCanvasV2.build_canvas(get_metadata(get_entity_by_id(id_)))) | ||
|
||
@staticmethod | ||
def build_canvas(metadata: dict[str, Any]) -> dict[str, Any]: | ||
entity = metadata['entity'] | ||
return { | ||
"@id": url_for( | ||
'api.iiif_canvas', id_=entity.id, version=2, _external=True), | ||
"@type": "sc:Canvas", | ||
"label": entity.name, | ||
"height": metadata['img_api']['height'], | ||
"width": metadata['img_api']['width'], | ||
"description": { | ||
"@value": entity.description, | ||
"@language": "en"}, | ||
"images": [IIIFImageV2.build_image(metadata)], | ||
"related": "", | ||
"thumbnail": { | ||
"@id": f'{metadata["img_url"]}/full/!200,200/0/default.jpg', | ||
"@type": "dctypes:Image", | ||
"format": "image/jpeg", | ||
"height": 200, | ||
"width": 200, | ||
"service": { | ||
"@context": "https://iiif.io/api/image/2/context.json", | ||
"@id": metadata['img_url'], | ||
"profile": metadata['img_api']['profile']}}} | ||
|
||
|
||
class IIIFImageV2(Resource): | ||
@staticmethod | ||
def get(id_: int) -> Response: | ||
return jsonify( | ||
IIIFImageV2.build_image(get_metadata(get_entity_by_id(id_)))) | ||
|
||
@staticmethod | ||
def build_image(metadata: dict[str, Any]) -> dict[str, Any]: | ||
id_ = metadata['entity'].id | ||
return { | ||
"@context": "https://iiif.io/api/presentation/2/context.json", | ||
"@id": | ||
url_for('api.iiif_image', id_=id_, version=2, _external=True), | ||
"@type": "oa:Annotation", | ||
"motivation": "sc:painting", | ||
"resource": { | ||
"@id": metadata['img_url'], | ||
"@type": "dctypes:Image", | ||
"format": "image/jpeg", | ||
"service": { | ||
"@context": "https://iiif.io/api/image/2/context.json", | ||
"@id": metadata['img_url'], | ||
"profile": metadata['img_api']['profile']}, | ||
"height": metadata['img_api']['height'], | ||
"width": metadata['img_api']['width']}, | ||
"on": | ||
url_for('api.iiif_canvas', id_=id_, version=2, _external=True)} | ||
|
||
|
||
class IIIFManifest(Resource): | ||
@staticmethod | ||
def get(version: int, id_: int) -> Response: | ||
operation = getattr(IIIFManifest, f'get_manifest_version_{version}') | ||
return jsonify(operation(id_)) | ||
|
||
@staticmethod | ||
def get_manifest_version_2(id_: int) -> dict[str, Any]: | ||
entity = get_entity_by_id(id_) | ||
return { | ||
"@context": "https://iiif.io/api/presentation/2/context.json", | ||
"@id": | ||
url_for( | ||
'api.iiif_manifest', | ||
id_=id_, | ||
version=2, | ||
_external=True), | ||
"@type": "sc:Manifest", | ||
"label": entity.name, | ||
"metadata": [], | ||
"description": [{ | ||
"@value": entity.description, | ||
"@language": "en"}], | ||
"license": get_license_name(entity), | ||
"attribution": "By OpenAtlas", | ||
"logo": get_logo(), | ||
"sequences": [ | ||
IIIFSequenceV2.build_sequence(get_metadata(entity))], | ||
"structures": []} | ||
|
||
|
||
def get_metadata(entity: Entity) -> dict[str, Any]: | ||
ext = '.tiff' if app.config['IIIF']['conversion'] \ | ||
else entity.get_file_ext() | ||
image_url = f"{app.config['IIIF']['url']}{entity.id}{ext}" | ||
req = requests.get(f"{image_url}/info.json") | ||
image_api = req.json() | ||
return {'entity': entity, 'img_url': image_url, 'img_api': image_api} | ||
|
||
|
||
def get_logo() -> dict[str, Any]: | ||
return { | ||
"@id": url_for( | ||
'api.display', | ||
filename=g.settings['logo_file_id'], | ||
_external=True), | ||
"service": { | ||
"@context": "https://iiif.io/api/image/2/context.json", | ||
"@id": url_for('overview', _external=True), | ||
"profile": "https://iiif.io/api/image/2/level2.json"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.