Skip to content

Commit

Permalink
moving labs API iiif catalog to prod service (#67)
Browse files Browse the repository at this point in the history
Uses the scrape API to produce results for `/` and `/collection.json` endpoints.

By default, if no query is provided, the `restrict_to_iiif` collections query is used which is `(mediatype:'texts' AND mediatype:'image')`. Additionally, `restrict_to_iiif` can be used to limit any other query to these collections (in attempt to produce results that are IIIF compatible). In the future, this should use `formats:` instead of `mediatype:` to include AV and produce a more complete and accurate set of compatible items.


---------

Co-authored-by: Glen Robson <[email protected]>
  • Loading branch information
mekarpeles and glenrobson authored Sep 29, 2024
1 parent 0d9a212 commit fa018e3
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 62 deletions.
35 changes: 22 additions & 13 deletions iiify/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from flask_cors import CORS
from flask_caching import Cache
from iiif2 import iiif, web
from .resolver import ia_resolver, create_manifest, create_manifest3, getids, collection, \
purify_domain, cantaloupe_resolver, create_collection3, IsCollection, create_annotations
from .resolver import ia_resolver, create_manifest, create_manifest3, scrape, \
collection, purify_domain, cantaloupe_resolver, create_collection3, IsCollection, \
create_annotations
from .configs import options, cors, approot, cache_root, media_root, \
cache_expr, version, image_server, cache_timeouts
from urllib.parse import quote
Expand Down Expand Up @@ -56,18 +57,27 @@ def mainentry():
@app.route('/iiif/')
def index():
"""Lists all available book and image items on Archive.org"""
cursor = request.args.get('cursor', '')
q = request.args.get('q', '')
return jsonify(getids(q, cursor=cursor))

cursor = request.args.get('cursor', '')
fields = request.args.get('fields', '')
sorts = request.args.get('sorts', '')
r = scrape(q, cursor=cursor, fields=fields, sorts=sorts, restrict_to_iiif=True)
return jsonify(r)


@app.route('/iiif/collection.json')
def catalog():
cursor = request.args.get('cursor', '')
q = request.args.get('q', '')
cursor = request.args.get('cursor', '')
fields = request.args.get('fields', '')
sorts = request.args.get('sorts', '')
domain = purify_domain(request.args.get('domain', request.url_root))
return ldjsonify(collection(domain, getids(q, limit, cursor)['ids']))
identifiers = [
i.get('identifier') for i in scrape(
q, cursor=cursor, fields=fields, sorts=sorts, restrict_to_iiif=True
).get('items')
]
return ldjsonify(collection(domain, identifiers))


@app.route('/iiif/cache')
Expand Down Expand Up @@ -99,16 +109,16 @@ def helper(identifier):
return render_template('helpers/image.html', identifier=identifier, cantaloupe_id=cantaloupe_id, esc_cantaloupe_id=esc_cantaloupe_id)
except ValueError:
abort(404)

elif mediatype == "audio" or mediatype == "etree":
return render_template('helpers/audio.html', identifier=identifier)
elif mediatype == "movies":
return render_template('helpers/movies.html', identifier=identifier)
elif mediatype == "texts":
return render_template('helpers/texts.html', identifier=identifier)
else:
else:
return render_template('helpers/unknown.html', identifier=identifier)


@app.route('/iiif/<identifier>')
def view(identifier):
Expand All @@ -129,7 +139,7 @@ def view(identifier):

@app.route('/iiif/3/<identifier>/collection.json')
@cache.cached(timeout=cache_timeouts["med"], forced_update=cache_bust)
def collection3(identifier):
def collection3JSON(identifier):
domain = purify_domain(request.args.get('domain', request.url_root))

try:
Expand Down Expand Up @@ -164,7 +174,7 @@ def collection3page(identifier, page):

@app.route('/iiif/<identifier>/collection.json')
@cache.cached(timeout=cache_timeouts["long"], forced_update=cache_bust)
def collection(identifier):
def collectionJSON(identifier):
return redirect(f'/iiif/3/{identifier}/collection.json', code=302)


Expand Down Expand Up @@ -239,7 +249,6 @@ def add_header(response):

def ldjsonify(data):
j = jsonify(data)
# j.headers.set('Access-Control-Allow-Origin', '*')
j.mimetype = "application/ld+json"
return j

Expand Down
Loading

0 comments on commit fa018e3

Please sign in to comment.