From 270be38d1e2c1847661cdac89bc9ecc3a10ce2fa Mon Sep 17 00:00:00 2001 From: Hell13Cat <46496367+Hell13Cat@users.noreply.github.com> Date: Tue, 26 May 2026 22:53:39 +0300 Subject: [PATCH] 0.0.1s --- README.md | 2 +- README_ru.md | 2 +- config.json | 5 ++++- run.py | 44 ++++++++++++++++++++++++++++++++++++++++---- system_module/db.py | 18 ++++++++++++++++++ 5 files changed, 64 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ce4bb68..a3328c6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Version Naming Rules: All technical versions are designated as snapshots (s) -All test versions are designated as alpha and beta (a, b) +All test versions are designated as beta (b) All pre-release and release versions are designated as release candidate and release (rc, r) diff --git a/README_ru.md b/README_ru.md index 7baa736..f7020ce 100644 --- a/README_ru.md +++ b/README_ru.md @@ -6,7 +6,7 @@ Все технические версии обозначаються как снапшоты (s) -Все тестовые версии обозначаються как альфа и бета (a, b) +Все тестовые версии обозначаються как бета (b) Все предрелизны и релизные версии обозначаються как кандидат в релиз и релиз (rc, r) diff --git a/config.json b/config.json index 9422d8c..3fdd915 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,8 @@ { - "port":8084, + "server":{ + "port":8084, + "count_page":25 + }, "gb":{ "id":"", "hash":"", diff --git a/run.py b/run.py index 10c8a2f..5b34a45 100644 --- a/run.py +++ b/run.py @@ -7,7 +7,8 @@ import os CONFIG_ROOT = json.load(open("config.json", "r", encoding="utf-8")) CONFIG_ROOT_S = json.load(open("config_gb.json", "r", encoding="utf-8")) -CONFIG_PORT = CONFIG_ROOT["port"] +CONFIG_PORT = CONFIG_ROOT["server"]["port"] +PAGINATION_COUNT = CONFIG_ROOT["server"]["count_page"] GB_ID = CONFIG_ROOT_S["gb"]["id"] GB_HASH = CONFIG_ROOT_S["gb"]["hash"] GB_HEADERS = CONFIG_ROOT["gb"]["headers"] @@ -26,7 +27,6 @@ def find_file(filename, file_folders): continue for file_path in folder_path.rglob(filename): return folder_path - return None @app.route("/") @@ -84,9 +84,45 @@ def dw_api(): @app.route("/api", methods=["GET", "POST"]) def api(): - + data = request.get_json() + if data["type"] == "post": + search_query = data["query"].split(" ") + search_rating = data["rating"].split("+") + results = database.get_search(search_query, search_rating) + if len(results) <= PAGINATION_COUNT: + results_send = {"results_info":{"total":len(results), "page":int(data["page"]), "count_page":PAGINATION_COUNT}, "results":results} + return jsonify(results_send) + else: + results_slile = results[int(data["page"])*PAGINATION_COUNT:(int(data["page"])+1)*PAGINATION_COUNT] + results_send = {"results_info":{"total":len(results), "page":int(data["page"]), "count_page":PAGINATION_COUNT}, "results":results_slile} + return jsonify(results_send) + elif data["type"] == "autocomplete": + tag_slise = data["q"] + result_autocomplete = database.get_autocomplete(tag_slise) + return jsonify(result_autocomplete) + else: + pass return "", 204 if __name__ == "__main__": - app.run(host="0.0.0.0", port=CONFIG_PORT) \ No newline at end of file + app.run(host="0.0.0.0", port=CONFIG_PORT) + +exit() + +DB.append({ + "md5": item.get("md5"), + "local_filename": local_filename, + "thumb_url": thumb_url, + "is_video": is_video, + "is_gif": is_gif, + "found": item.get("found_on_gelbooru", False), + "tags": tags, + "rating": data.get("rating", "N/A"), + "score": data.get("score", 0), + "timestamp": timestamp, + "display_date": display_date, + "source": data.get("source", ""), + "width": data.get("width", 0), + "height": data.get("height", 0) +}) \ No newline at end of file diff --git a/system_module/db.py b/system_module/db.py index fce8d73..bba05af 100644 --- a/system_module/db.py +++ b/system_module/db.py @@ -1,6 +1,7 @@ from tinydb import TinyDB, Query import os import json +from collections import Counter class DB: def __init__(self): @@ -22,6 +23,7 @@ class DB: return self.db.all() def get_search(self, ratings, tags): + ratings results = self.db.search( self.File.rating.one_of(self.ratings) & self.File.tags.any(self.tags) @@ -32,5 +34,21 @@ class DB: results = self.db.search(self.File.tags == []) return results + def get_autocomplete(self, tag_slise): + counter = Counter() + for record in self.db.all(): + counter.update(record.get("tags", [])) + results = [ + { + "tag": tag, + "count": count + } + for tag, count in counter.items() + if tag.lower().startswith(prefix) + ] + results.sort(key=lambda x: x["count"], reverse=True) + top_10 = results[:10] + return top_10 + def edit_data(self, id_file, edit_data): self.db.update(self.edit_data, self.File.md5 == self.id_file) \ No newline at end of file