0.0.1s
This commit is contained in:
@@ -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)
|
||||
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)
|
||||
})
|
||||
Reference in New Issue
Block a user