Package: oarepo-iiif
OAREPO IIIFThis package adds support for input loaders for IIIF serverRationaleWe would like to add support for loading images from non-image source. For example,
loading n-th image from a PDF file, converting data into graphs etc.Invenio support for IIIFInvenio has support for IIIF server via invenio-iiif package. Unfortunately there is no
extensibility mechanism for loading images from non-image sources.This package adds this support.UsageOpener functionsCreate an opener and register it to entry pointoarepo_iiif.openers. Theuuidcontains an identification of the image. It is up to you to parse and interpret it.def pdf_opener(uuid, app=None, **kwargs):   # kwargs currently empty but keep them for extensibility
    return binary stream of image data or None if can not handle the uuidCheck functionsIf the opener loads data not from file buckets but from another location,
you have to register a function that checks access (and raises werkzeug exception
if the access is denied). The entry point for this function isoarepo_iiif.checks.def pdf_check(uuid, app=None, **kwargs):        # kwargs might contain 'version', 'region', 'size', 'rotation', 'quality', 'image_format'
    """
        check permissions and return 
            * True if the access is ok 
            * None if can not handle
            * raise an exception if access denied
    """
    return TrueSeerest testfor an example of these functions.Indentifier creating functions (optional)Optionally register an identifier creating function under entrypointoarepo_iiif.identifier_makers.
The function gets invenio-record-files' FileObject and Record and should produce identifier
used in checks & openers.def pdf_identifier(record: Record, file:FileObject, pid:PersistentIdentifier, app=None, **kwargs):
    """
        return crafted PDF identifier
    """
    return 'pdf-images:{recid}:{key}'.format(recid=record.id, key=file['key'])Then power up the server and hit IIIF url:curlhttps://127.0.0.1:5000/api/iiif/v2/<uuid>/<region>/<size>/<rotation>/<quality>.<format>Integration withoarepo-records-draftoarepo-records-draftadds support for uploading attachments with easier security checks than
those ininvenio-files-restorinvenio-record-files.Moreover, it provides a set of callbacks that are called whenever a file is associated to a record.
Ifoarepo-records-draftis detected, a custom handler is registered forattachment_uploaded_before_commit.The handlerHow it works (for library developers)As extensibility mechanism is not available, this library overrides invneio-iiifuuid_to_image_openerandapi_decorator_callbackin theapp_loadedcallback. Keep this in mind if you have libraries
that perform similar task.@app_loaded.connectdefloaded(sender,app=None,**kwargs):withapp.app_context():current_oarepo_iiif=app.extensions['oarepo-iiif']iiif_ext=current_app.extensions['invenio-iiif'].iiif_ext# replace openerprev_opener=iiif_ext.uuid_to_image_openeriiif_ext.uuid_to_image_opener_handler(lambda*args,**akwargs:current_oarepo_iiif.open(*args,app=app,**akwargs)orprev_opener(*args,**akwargs))# replace decorator handlerprev_decorator_handler=iiif_ext.api_decorator_callbackdefdecorator_handler(*args,**akwargs):ret=current_oarepo_iiif.check(*args,app=app,**akwargs)ifretisnotNone:returnretreturnprev_decorator_handler(*args,**akwargs)iiif_ext.api_decorator_handler(decorator_handler)