Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/origin.py
Show First 20 Lines • Show All 211 Lines • ▼ Show 20 Lines | .. http:get:: /api/1/origin/search/(url_pattern)/ | ||||
**Example:** | **Example:** | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
:swh_web_api:`origin/search/python/?limit=2` | :swh_web_api:`origin/search/python/?limit=2` | ||||
""" | """ | ||||
result = {} | result = {} | ||||
offset = int(request.query_params.get('offset', '0')) | |||||
limit = min(int(request.query_params.get('limit', '70')), 1000) | limit = min(int(request.query_params.get('limit', '70')), 1000) | ||||
page_token = request.query_params.get('page_token') | |||||
with_visit = request.query_params.get('with_visit', 'false') | with_visit = request.query_params.get('with_visit', 'false') | ||||
results = api_lookup(service.search_origin, url_pattern, offset, limit, | (results, page_token) = api_lookup( | ||||
bool(strtobool(with_visit)), | service.search_origin, url_pattern, limit, | ||||
bool(strtobool(with_visit)), page_token, | |||||
enrich_fn=_enrich_origin) | enrich_fn=_enrich_origin) | ||||
nb_results = len(results) | if page_token is not None: | ||||
if nb_results == limit: | |||||
query_params = {} | query_params = {} | ||||
query_params['offset'] = offset + limit | |||||
query_params['limit'] = limit | query_params['limit'] = limit | ||||
query_params['page_token'] = page_token | |||||
result['headers'] = { | result['headers'] = { | ||||
'link-next': reverse('api-1-origin-search', | 'link-next': reverse('api-1-origin-search', | ||||
url_args={'url_pattern': url_pattern}, | url_args={'url_pattern': url_pattern}, | ||||
query_params=query_params) | query_params=query_params) | ||||
} | } | ||||
result.update({ | result.update({ | ||||
▲ Show 20 Lines • Show All 262 Lines • Show Last 20 Lines |