diff --git a/app/apps.py b/app/apps.py index 1e8d7a6..dcc9c08 100644 --- a/app/apps.py +++ b/app/apps.py @@ -51,6 +51,9 @@ def load_appstream(): p.sadd("types:index", type) p.sadd(f"types:{type}", redis_key) + if extends := apps[appid].get("extends"): + p.sadd(f"addons:{extends}", redis_key) + if categories := apps[appid].get("categories"): for category in categories: p.sadd("categories:index", category) @@ -62,6 +65,7 @@ def load_appstream(): f"fts:{appid}", f"summary:{appid}", f"app_stats:{appid}", + f"addons:{appid}", ) db.redis_search.delete_document(f"fts:{appid}") @@ -103,6 +107,16 @@ def get_developer(developer: str): return [] +def get_addons(appid: str): + if index := db.redis_conn.smembers(f"addons:{appid}"): + json_appdata = db.redis_conn.mget(index) + appdata = [json.loads(app) for app in json_appdata] + + return [(app["id"]) for app in appdata] + else: + return [] + + def search(query: str): if results := db.search(query): appids = tuple(doc_id.replace("fts", "apps") for doc_id in results) diff --git a/app/main.py b/app/main.py index f495cf3..7fcb7f7 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,4 @@ +from collections import defaultdict from functools import lru_cache import sentry_sdk @@ -122,6 +123,21 @@ def get_developer( return sorted_ids +@app.get("/addon/{appid}") +def get_addons(appid: str): + ids = apps.get_addons(appid) + + addon_appstreams = defaultdict() + for addonid in ids: + addon_appstreams[addonid] = db.get_json_key(f"apps:{addonid}") + sorted_ids = sorted( + ids, + key=lambda appid: addon_appstreams[appid].get("name", "Unknown"), + ) + + return sorted_ids + + @app.get("/appstream") def list_appstream(type: schemas.Type = schemas.Type.Desktop): return apps.list_appstream(type)