Repos / pytaku / e6dfe75582
commit e6dfe755823f9a8eb7db60a7ab2e697e3b3e128a
Author: Bùi Thành Nhân <hi@imnhan.com>
Date: Sat Sep 4 00:51:31 2021 +0700
tweak search so mangasee results come first
diff --git a/src/pytaku/js-src/models.js b/src/pytaku/js-src/models.js
index 221681f..b3d225c 100644
--- a/src/pytaku/js-src/models.js
+++ b/src/pytaku/js-src/models.js
@@ -107,8 +107,8 @@ const SearchModel = {
params: { query },
})
.then((resp) => {
- SearchModel.cache[query] = resp;
- SearchModel.result = resp;
+ SearchModel.cache[query] = resp.results;
+ SearchModel.result = resp.results;
})
.catch((err) => {
console.log("TODO", err);
diff --git a/src/pytaku/js-src/routes/search.js b/src/pytaku/js-src/routes/search.js
index 6551504..78a8971 100644
--- a/src/pytaku/js-src/routes/search.js
+++ b/src/pytaku/js-src/routes/search.js
@@ -11,7 +11,7 @@ const Search = {
"div.content",
SearchModel.isLoading
? m(LoadingMessage)
- : Object.entries(SearchModel.result).map(([site, titles]) =>
+ : SearchModel.result.map(({ site, titles }) =>
m("div", [
m("h1.search--site-heading", site),
titles
diff --git a/src/pytaku/main.py b/src/pytaku/main.py
index 7246224..74661d3 100644
--- a/src/pytaku/main.py
+++ b/src/pytaku/main.py
@@ -382,10 +382,12 @@ def api_follows():
def api_search(query):
results = search_title_all_sites(query)
- if "mangadex" in results:
- for title in results["mangadex"]:
- title["thumbnail"] = proxied(title["thumbnail"])
- return results
+ for result in results:
+ if result["site"] == "mangadex":
+ for title in result["titles"]:
+ title["thumbnail"] = proxied(title["thumbnail"])
+ break
+ return {"results": results}
@app.route("/api/follow", methods=["POST"])
diff --git a/src/pytaku/source_sites.py b/src/pytaku/source_sites.py
index edc1821..44ddd38 100644
--- a/src/pytaku/source_sites.py
+++ b/src/pytaku/source_sites.py
@@ -59,7 +59,7 @@ def search_title_all_sites(query):
I should really look into proper type annotations huh.
"""
site_names = ("mangasee", "mangadex")
- results = {}
+ results = []
def safe_search(site_name, query):
try:
@@ -79,6 +79,6 @@ def safe_search(site_name, query):
for future in as_completed(future_to_site_name):
site_results = future.result()
site_name = future_to_site_name[future]
- results[site_name] = site_results
+ results.append({"site": site_name, "titles": site_results})
return results