7s
This commit is contained in:
@@ -7,5 +7,8 @@
|
|||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||||
"Referer": "https://gelbooru.com/"
|
"Referer": "https://gelbooru.com/"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"file":{
|
||||||
|
"repos":["data/files"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,30 +2,53 @@ 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
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
|
|
||||||
CONFIG_ROOT = json.load(open("config.json", "r", encoding="utf-8"))
|
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_ROOT_S = json.load(open("config_gb.json", "r", encoding="utf-8"))
|
||||||
CONFIG_PORT = CONFIG_ROOT["port"]
|
CONFIG_PORT = CONFIG_ROOT["port"]
|
||||||
GB_ID = CONFIG_ROOT["gb"]["id"]
|
GB_ID = CONFIG_ROOT_S["gb"]["id"]
|
||||||
GB_HASH = CONFIG_ROOT["gb"]["hash"]
|
GB_HASH = CONFIG_ROOT_S["gb"]["hash"]
|
||||||
GB_HEADERS = CONFIG_ROOT["gb"]["headers"]
|
GB_HEADERS = CONFIG_ROOT["gb"]["headers"]
|
||||||
|
FILE_FOLDERS = CONFIG_ROOT["file"]["repos"]
|
||||||
|
THUMB_FOLDER = "data/thumb"
|
||||||
|
|
||||||
gb = gelbooru.GB(GB_ID, GB_HASH, GB_HEADERS)
|
gb = gelbooru.GB(GB_ID, GB_HASH, GB_HEADERS)
|
||||||
log = logger.Logger()
|
log = logger.Logger()
|
||||||
database = db.DB()
|
database = db.DB()
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
def find_file(filename, file_folders):
|
||||||
|
for folder in file_folders:
|
||||||
|
folder_path = Path(folder)
|
||||||
|
if not folder_path.exists():
|
||||||
|
continue
|
||||||
|
for file_path in folder_path.rglob(filename):
|
||||||
|
return folder_path
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/analytics")
|
@app.route("/analytics")
|
||||||
def analytics():
|
def analytics():
|
||||||
return render_template("analytics.html")
|
return render_template("analytics.html")
|
||||||
|
|
||||||
|
@app.route("/post/<path:post_id>")
|
||||||
|
def post(post_id):
|
||||||
|
return render_template("post.html")
|
||||||
|
|
||||||
|
@app.route('/file/<path:filename>')
|
||||||
|
def serve_image(filename):
|
||||||
|
folder_path = find_file(filename, FILE_FOLDERS)
|
||||||
|
return send_from_directory(folder_path, filename)
|
||||||
|
|
||||||
|
@app.route('/thumb/<path:filename>')
|
||||||
|
def serve_thumb(filename):
|
||||||
|
return send_from_directory(THUMB_FOLDER, filename)
|
||||||
|
|
||||||
@app.route("/dw_api", methods=['POST'])
|
@app.route("/dw_api", methods=['POST'])
|
||||||
def dw_api():
|
def dw_api():
|
||||||
@@ -59,12 +82,6 @@ def dw_api():
|
|||||||
log.send("error", "all", error_message)
|
log.send("error", "all", error_message)
|
||||||
return jsonify({'status': 'error', 'message': error_message}), 500
|
return jsonify({'status': 'error', 'message': error_message}), 500
|
||||||
|
|
||||||
|
|
||||||
@app.route("/post/<path:post_id>")
|
|
||||||
def post(post_id):
|
|
||||||
return render_template("post.html")
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api", methods=["GET", "POST"])
|
@app.route("/api", methods=["GET", "POST"])
|
||||||
def api():
|
def api():
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user