0.0.5s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from system_module import db, gelbooru, logger
|
||||
from flask import Flask, render_template, jsonify, send_from_directory, render_template_string
|
||||
from flask import Flask, render_template, jsonify, send_from_directory, render_template_string, request
|
||||
import json
|
||||
import requests
|
||||
from pathlib import Path
|
||||
@@ -13,11 +13,11 @@ GB_ID = CONFIG_ROOT_S["gb"]["id"]
|
||||
GB_HASH = CONFIG_ROOT_S["gb"]["hash"]
|
||||
GB_HEADERS = CONFIG_ROOT["gb"]["headers"]
|
||||
FILE_FOLDERS = CONFIG_ROOT["file"]["repos"]
|
||||
THUMB_FOLDER = "data/thumb"
|
||||
THUMB_FOLDER = "data_test/thumb"
|
||||
|
||||
gb = gelbooru.GB(GB_ID, GB_HASH, GB_HEADERS)
|
||||
log = logger.Logger()
|
||||
database = db.DB()
|
||||
database = db.DB(True)
|
||||
app = Flask(__name__)
|
||||
|
||||
def find_file(filename, file_folders):
|
||||
@@ -85,10 +85,15 @@ 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 data["type"] == "search":
|
||||
search_query = data["query"]
|
||||
search_rating = data["rating"]
|
||||
if search_query == "" and search_rating == "e+q+s+g":
|
||||
results = database.get_all()
|
||||
else:
|
||||
search_query = search_query.split(" ")
|
||||
search_rating = search_rating.split("+")
|
||||
results = database.get_search(search_rating, search_query)
|
||||
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)
|
||||
@@ -100,6 +105,10 @@ def api():
|
||||
tag_slise = data["q"]
|
||||
result_autocomplete = database.get_autocomplete(tag_slise)
|
||||
return jsonify(result_autocomplete)
|
||||
elif data["type"] == "post":
|
||||
post_id = data["post_id"]
|
||||
result_post = database.get_from_id(post_id)
|
||||
return jsonify(result_post)
|
||||
else:
|
||||
pass
|
||||
return "", 204
|
||||
|
||||
Reference in New Issue
Block a user