Skip to content

Commit 240072b

Browse files
authored
fix /iiif & catalog.json
1 parent 9443b39 commit 240072b

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

iiify/app.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import time
55
import requests
66
from flask import Flask, send_file, jsonify, abort, request, render_template, redirect
7-
from flask_limiter import Limiter
8-
from flask_limiter.util import get_remote_address
97
from flask.ext.cors import CORS
108
from iiif2 import iiif, web
119
from resolver import ia_resolver, create_manifest, getids, collection, \
@@ -17,8 +15,7 @@
1715

1816
app = Flask(__name__)
1917
cors = CORS(app) if cors else None
20-
#limiter = Limiter(app, key_func=get_remote_address,
21-
# default_limits=['10000 per day', '1000 per hour'])
18+
2219

2320
def sprite_concat(imgs):
2421
from PIL import Image
@@ -39,9 +36,9 @@ def sprite_concat(imgs):
3936
@app.route('/iiif/')
4037
def index():
4138
"""Lists all available book and image items on Archive.org"""
42-
cursor = request.args.get('cursor', '')
39+
page = request.args.get('page', 1)
4340
q = request.args.get('q', '')
44-
return jsonify(getids(q, cursor=cursor))
41+
return jsonify(getids(q, page=page))
4542

4643
@app.route('/iiif/url2iiif')
4744
def url2iiif():
@@ -59,10 +56,13 @@ def url2iiif():
5956

6057
@app.route('/iiif/collection.json')
6158
def catalog():
62-
cursor = request.args.get('cursor', '')
6359
q = request.args.get('q', '')
60+
page = request.args.get('page', 1)
61+
limit = request.args.get('limit', 100)
6462
domain = purify_domain(request.args.get('domain', request.url_root))
65-
return ldjsonify(collection(domain, getids(q, limit, cursor)['ids']))
63+
docs = getids(q, page=page, limit=limit).get('response', {}).get('docs', [])
64+
ids = (doc['identifier'] for doc in docs)
65+
return ldjsonify(collection(domain, ids))
6666

6767
@app.route('/iiif/cache')
6868
def cache():

iiify/resolver.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@
1616
def purify_domain(domain):
1717
return domain if domain.endswith('/iiif/') else domain + 'iiif/'
1818

19-
def getids(q, limit=1000, cursor=''):
20-
r = requests.get('%s/iiif' % apiurl, params={
21-
'q': q,
22-
'limit': limit,
23-
'cursor': cursor
24-
}, allow_redirects=True, timeout=None)
25-
return r.json()
26-
19+
def getids(query, page=1, limit=100, security=True, sort='', fields='identifier,title'):
20+
limit = min(limit, 1000)
21+
params = {
22+
'q': query,
23+
'rows': limit,
24+
'sort': sort,
25+
'page': page,
26+
'fl[]': fields,
27+
'output': 'json',
28+
}
29+
return requests.get(
30+
"%s/advancedsearch.php" % ARCHIVE, params=params,
31+
allow_redirects=True, timeout=None
32+
).json()
2733

2834
def collection(domain, identifiers, label='Custom Archive.org IIIF Collection'):
2935
cs = {

0 commit comments

Comments
 (0)