Skip to content

Commit fa018e3

Browse files
moving labs API iiif catalog to prod service (#67)
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]>
1 parent 0d9a212 commit fa018e3

File tree

2 files changed

+116
-62
lines changed

2 files changed

+116
-62
lines changed

iiify/app.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from flask_cors import CORS
88
from flask_caching import Cache
99
from iiif2 import iiif, web
10-
from .resolver import ia_resolver, create_manifest, create_manifest3, getids, collection, \
11-
purify_domain, cantaloupe_resolver, create_collection3, IsCollection, create_annotations
10+
from .resolver import ia_resolver, create_manifest, create_manifest3, scrape, \
11+
collection, purify_domain, cantaloupe_resolver, create_collection3, IsCollection, \
12+
create_annotations
1213
from .configs import options, cors, approot, cache_root, media_root, \
1314
cache_expr, version, image_server, cache_timeouts
1415
from urllib.parse import quote
@@ -56,18 +57,27 @@ def mainentry():
5657
@app.route('/iiif/')
5758
def index():
5859
"""Lists all available book and image items on Archive.org"""
59-
cursor = request.args.get('cursor', '')
6060
q = request.args.get('q', '')
61-
return jsonify(getids(q, cursor=cursor))
62-
61+
cursor = request.args.get('cursor', '')
62+
fields = request.args.get('fields', '')
63+
sorts = request.args.get('sorts', '')
64+
r = scrape(q, cursor=cursor, fields=fields, sorts=sorts, restrict_to_iiif=True)
65+
return jsonify(r)
6366

6467

6568
@app.route('/iiif/collection.json')
6669
def catalog():
67-
cursor = request.args.get('cursor', '')
6870
q = request.args.get('q', '')
71+
cursor = request.args.get('cursor', '')
72+
fields = request.args.get('fields', '')
73+
sorts = request.args.get('sorts', '')
6974
domain = purify_domain(request.args.get('domain', request.url_root))
70-
return ldjsonify(collection(domain, getids(q, limit, cursor)['ids']))
75+
identifiers = [
76+
i.get('identifier') for i in scrape(
77+
q, cursor=cursor, fields=fields, sorts=sorts, restrict_to_iiif=True
78+
).get('items')
79+
]
80+
return ldjsonify(collection(domain, identifiers))
7181

7282

7383
@app.route('/iiif/cache')
@@ -99,16 +109,16 @@ def helper(identifier):
99109
return render_template('helpers/image.html', identifier=identifier, cantaloupe_id=cantaloupe_id, esc_cantaloupe_id=esc_cantaloupe_id)
100110
except ValueError:
101111
abort(404)
102-
112+
103113
elif mediatype == "audio" or mediatype == "etree":
104114
return render_template('helpers/audio.html', identifier=identifier)
105115
elif mediatype == "movies":
106116
return render_template('helpers/movies.html', identifier=identifier)
107117
elif mediatype == "texts":
108118
return render_template('helpers/texts.html', identifier=identifier)
109-
else:
119+
else:
110120
return render_template('helpers/unknown.html', identifier=identifier)
111-
121+
112122

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

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

135145
try:
@@ -164,7 +174,7 @@ def collection3page(identifier, page):
164174

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

170180

@@ -239,7 +249,6 @@ def add_header(response):
239249

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

0 commit comments

Comments
 (0)