1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

memento/api: add a new /collinfo.json end-point, enabled with 'enable_coll_info' config setting, which returns

the value fo collinfo.json template. Default template returns an entry for each handler route,
including the route path (id), title (name) and memento timegate and timemap paths, to be used with
an aggregator. Using a custom 'info_json' template can specify a different collinfo template, alternative to #69 (local aggregation)
Closes #146
This commit is contained in:
Ilya Kreymer 2015-11-04 15:36:44 -08:00
parent dc74b14af0
commit d98c1f6cf7
6 changed files with 41 additions and 3 deletions

View File

@ -23,6 +23,7 @@ paths:
proxy_cert_download_html: proxy_cert_download.html
proxy_select_html: proxy_select.html
info_json: collinfo.json
templates_dirs:
- templates
@ -49,6 +50,7 @@ not_found_html: not_found.html
proxy_cert_download_html: proxy_cert_download.html
proxy_select_html: proxy_select.html
info_json: collinfo.json
static_default_prefix: &static_default_prefix static/__pywb
static_shared_prefix: static/__shared

View File

@ -23,9 +23,12 @@ class ArchivalRouter(object):
self.home_view = kwargs.get('home_view')
self.error_view = kwargs.get('error_view')
self.info_view = kwargs.get('info_view')
self.urlrewriter_class = (kwargs.get('config', {}).
get('urlrewriter_class', UrlRewriter))
config = kwargs.get('config', {})
self.urlrewriter_class = config.get('urlrewriter_class', UrlRewriter)
self.enable_coll_info = config.get('enable_coll_info', False)
def __call__(self, env):
request_uri = self.ensure_rel_uri_set(env)
@ -43,6 +46,13 @@ class ArchivalRouter(object):
if request_uri in ['/', '/index.html', '/index.htm']:
return self.render_home_page(env)
if self.enable_coll_info and request_uri in ['/collinfo.json']:
params = env.get('pywb.template_params', {})
host = WbRequest.make_host_prefix(env)
return self.info_view.render_response(env=env, host=host, routes=self.routes,
content_type='application/json',
**params)
return self.fallback(env, self) if self.fallback else None
def parse_request(self, route, env, matcher, coll, request_uri,

View File

@ -0,0 +1,15 @@
[
{% for route in routes %}
{% if route | is_wb_handler %}
{{ ',' if notfirst else '' }}
{
"id": "{{ route.path }}",
"name": "{{ route.user_metadata.title if route.user_metadata.title else route.path }}",
"timegate": "{{ host }}/{{route.path}}/",
"timemap": "{{ host }}/{{route.path}}/timemap/*/"
}
{% set notfirst = true %}
{% endif %}
{% endfor %}
]

View File

@ -381,5 +381,6 @@ def create_wb_router(passed_config=None):
abs_path=config.get('absolute_paths', True),
home_view=init_view(config, 'home_html'),
error_view=init_view(config, 'error_html'),
info_view=init_view(config, 'info_json'),
config=config
)

View File

@ -121,6 +121,10 @@ proxy_options:
use_client_rewrite: true
use_wombat: true
#enable coll info JSON
enable_coll_info: true
# enable cdx server api for querying cdx directly (experimental)
#enable_cdx_api: True
# or specify suffix

View File

@ -477,7 +477,13 @@ class TestWbIntegration(BaseIntegration):
assert resp.status_int == 400
assert 'Invalid Url: http://?abc' in resp.body
#def test_invalid_config(self):
def test_coll_info_json(self):
resp = self.testapp.get('/collinfo.json')
assert resp.content_type == 'application/json'
assert len(resp.json) == 9
#def test_invalid_config(self):
# with raises(IOError):
# init_app(create_wb_router,
# load_yaml=True,