mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
[fix] dockerhub: switch to new api path
Co-authored-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
18c3e08837
commit
0642c5434a
1 changed files with 24 additions and 12 deletions
|
@ -19,14 +19,17 @@ about = {
|
||||||
categories = ['it', 'packages'] # optional
|
categories = ['it', 'packages'] # optional
|
||||||
paging = True
|
paging = True
|
||||||
|
|
||||||
base_url = "https://hub.docker.com/"
|
base_url = "https://hub.docker.com"
|
||||||
search_url = base_url + "api/content/v1/products/search?{query}&type=image&page_size=25"
|
page_size = 10
|
||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
|
args = {
|
||||||
params['url'] = search_url.format(query=urlencode(dict(q=query, page=params["pageno"])))
|
"query": query,
|
||||||
params["headers"]["Search-Version"] = "v3"
|
"from": page_size * (params['pageno'] - 1),
|
||||||
|
"size": page_size,
|
||||||
|
}
|
||||||
|
params['url'] = f"{base_url}/api/search/v3/catalog/search?{urlencode(args)}"
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
@ -36,23 +39,32 @@ def response(resp):
|
||||||
resp: requests response object
|
resp: requests response object
|
||||||
'''
|
'''
|
||||||
results = []
|
results = []
|
||||||
body = resp.json()
|
json_resp = resp.json()
|
||||||
|
|
||||||
for item in body.get("summaries", []):
|
for item in json_resp.get("results", []):
|
||||||
filter_type = item.get("filter_type")
|
image_source = item.get("source")
|
||||||
is_official = filter_type in ["store", "official"]
|
is_official = image_source in ["store", "official"]
|
||||||
|
|
||||||
|
popularity_infos = [f"{item.get('star_count', 0)} stars"]
|
||||||
|
|
||||||
|
architectures = []
|
||||||
|
for rate_plan in item.get("rate_plans", []):
|
||||||
|
pull_count = rate_plan.get("repositories", [{}])[0].get("pull_count")
|
||||||
|
if pull_count:
|
||||||
|
popularity_infos.insert(0, f"{pull_count} pulls")
|
||||||
|
architectures.extend(arch['name'] for arch in rate_plan.get("architectures", []) if arch['name'])
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
'template': 'packages.html',
|
'template': 'packages.html',
|
||||||
'url': base_url + ("_/" if is_official else "r/") + item.get("slug", ""),
|
'url': base_url + ("/_/" if is_official else "/r/") + item.get("slug", ""),
|
||||||
'title': item.get("name"),
|
'title': item.get("name"),
|
||||||
'content': item.get("short_description"),
|
'content': item.get("short_description"),
|
||||||
'thumbnail': item["logo_url"].get("large") or item["logo_url"].get("small"),
|
'thumbnail': item["logo_url"].get("large") or item["logo_url"].get("small"),
|
||||||
'package_name': item.get("name"),
|
'package_name': item.get("name"),
|
||||||
'maintainer': item["publisher"].get("name"),
|
'maintainer': item["publisher"].get("name"),
|
||||||
'publishedDate': parser.parse(item.get("updated_at") or item.get("created_at")),
|
'publishedDate': parser.parse(item.get("updated_at") or item.get("created_at")),
|
||||||
'popularity': item.get("pull_count", "0") + " pulls",
|
'popularity': ', '.join(popularity_infos),
|
||||||
'tags': [arch['name'] for arch in item["architectures"]],
|
'tags': architectures,
|
||||||
}
|
}
|
||||||
results.append(result)
|
results.append(result)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue