0.0.1s
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
|
||||
Все технические версии обозначаються как снапшоты (s)
|
||||
|
||||
Все тестовые версии обозначаються как альфа и бета (a, b)
|
||||
Все тестовые версии обозначаються как бета (b)
|
||||
|
||||
Все предрелизны и релизные версии обозначаються как кандидат в релиз и релиз (rc, r)
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"server":{
|
||||
"port":8084,
|
||||
"count_page":25
|
||||
},
|
||||
"gb":{
|
||||
"id":"",
|
||||
"hash":"",
|
||||
|
||||
@@ -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)
|
||||
|
||||
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)
|
||||
})
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user