This commit is contained in:
p23 2024-11-19 15:29:01 +00:00
parent 0908b836d3
commit d381d1a743
9 changed files with 25 additions and 28 deletions

8
app.py
View File

@ -1,6 +1,6 @@
import os import os
from flask import Flask, jsonify from flask import Flask
from bcrypt import checkpw, gensalt, hashpw from bcrypt import checkpw, gensalt, hashpw
from sqlalchemy import create_engine from sqlalchemy import create_engine
@ -21,9 +21,9 @@ PLATFORM_ROOT_PASSWORD = os.getenv("PLATFORM_ROOT_PASSWORD", None)
# env checker # env checker
errmsg = [] errmsg = []
if JWT_KEY is None or len(JWT_KEY) == 0: if JWT_KEY is None or len(JWT_KEY) == 0:
errmsg.append("Invalid JWT_KEY") errmsg.append("Invalid JWT_KEY")
if PLATFORM_ROOT_PASSWORD is None or len(PLATFORM_ROOT_PASSWORD) == 0: if PLATFORM_ROOT_PASSWORD is None or len(PLATFORM_ROOT_PASSWORD) == 0:
errmsg.append("Invalid PLATFORM_ROOT_PASSWORD") errmsg.append("Invalid PLATFORM_ROOT_PASSWORD")
if len(errmsg): if len(errmsg):
print(f"Env check failed: {errmsg}") print(f"Env check failed: {errmsg}")
@ -71,4 +71,4 @@ def index():
# app run # app run
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=False) app.run(host="0.0.0.0", port=5000, debug=False)

View File

@ -235,7 +235,7 @@ def setting_get():
@admin.route("/setting", methods=["POST"]) @admin.route("/setting", methods=["POST"])
@role_required(["setting.edit"]) @role_required(["setting.edit"])
def setting_edit(): def setting_edit():
opuser = g.opuser opuser = g.opuser.user
req = request.json req = request.json
d = None d = None

View File

@ -12,7 +12,7 @@ log = Blueprint('log', __name__)
def listlog(): def listlog():
# variables # variables
if request.args.get("start") is None or request.args.get("count") is None or \ if request.args.get("start") is None or request.args.get("count") is None or \
request.args.get("start").isdigit()==False or request.args.get("count").isdigit()==False: not request.args.get("start").isdigit() or not request.args.get("count").isdigit():
return error("Arguments error"), 400 return error("Arguments error"), 400
rst = int(request.args.get("start")) rst = int(request.args.get("start"))
count = int(request.args.get("count")) count = int(request.args.get("count"))

View File

@ -1 +1 @@
{"Check_Before_Post": true, "JWT_Valid_Time": 604800, "Niming_Max_Word": 500, "Attachment_Count": 5, "Attachment_Size": 209715200, "Allowed_MIME": ["image/jpeg", "image/pjpeg", "image/png", "image/heic", "image/heif", "video/mp4", "video/quicktime", "video/hevc", "image/gif", "image/webp"]} {"Check_Before_Post": false, "JWT_Valid_Time": 604800, "Niming_Max_Word": 500, "Attachment_Count": 5, "Attachment_Size": 209715200, "Allowed_MIME": ["image/jpeg", "image/pjpeg", "image/png", "image/heic", "image/heif", "video/mp4", "video/quicktime", "video/hevc", "image/gif", "image/webp"]}

View File

@ -11,12 +11,12 @@ class db:
_engine = None _engine = None
@classmethod @classmethod
def __init__(self, engine): def __init__(cls, engine):
self._engine = engine cls._engine = engine
@classmethod @classmethod
def getsession(self): def getsession(cls):
Session = sessionmaker(bind=self._engine) Session = sessionmaker(bind=cls._engine)
return Session() return Session()
# role (general) (owner) (admin) # role (general) (owner) (admin)
@ -56,7 +56,7 @@ def solo_article_fetcher(role:str, key) -> Tuple[Dict,int]: # admin, owner, gene
def multi_article_fetcher(role:str, start:str, count:str) -> Tuple[Response, int]: # general, admin def multi_article_fetcher(role:str, start:str, count:str) -> Tuple[Response, int]: # general, admin
# checker # checker
if start is None or count is None or \ if start is None or count is None or \
start.isdigit()==False or count.isdigit()==False: not start.isdigit() or not count.isdigit():
return error("Arguments error"), 400 return error("Arguments error"), 400
start = int(start) start = int(start)
count = int(count) count = int(count)

View File

@ -1,2 +1,2 @@
def ighelper(): def ighelper():
pass pass

View File

@ -1,21 +1,16 @@
from utils import pgclass from utils import pgclass
from utils.dbhelper import db from utils.dbhelper import db
from utils.platform_consts import EVENT_TYPE_GENERAL, EVENT_TYPE_ADMIN, EVENT_TYPE_SERVER from utils.platform_consts import EVENT_TYPE
def logger(type, message): def logger(type, message):
table = pgclass.SQLlog table = pgclass.SQLlog
flag = False flag = False
# new post & del post for etl in EVENT_TYPE:
if type in EVENT_TYPE_GENERAL: if type in EVENT_TYPE[etl]:
flag = True flag = True
log = table(source = "general", message = message) log = table(source = etl, message = message)
elif type in EVENT_TYPE_ADMIN: break
flag = True
log = table(source = "admin", message = message)
elif type in EVENT_TYPE_SERVER:
flag = True
log = table(source = "server", message = message)
# session.add # session.add
if flag: if flag:

View File

@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, String, TIMESTAMP, func, BIGINT, LargeBinary, ARRAY from sqlalchemy import Column, String, TIMESTAMP, func, BIGINT, LargeBinary, ARRAY
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base() Base = declarative_base()

View File

@ -3,9 +3,11 @@ PLIST = ["article.read", "article.pend", "article.del", "setting.edit"] # no per
PLIST_ROOT = PLIST + ["usermgr"] PLIST_ROOT = PLIST + ["usermgr"]
# event type # event type
EVENT_TYPE_GENERAL = ["newpost", "delpost"] EVENT_TYPE = {
EVENT_TYPE_ADMIN = ["login", "user.create", "user.delete", "article.delete", "article.pend", "setting.modify"] "general": ["newpost", "delpost"],
EVENT_TYPE_SERVER = ["server.start"] "admin": ["login", "user.create", "user.delete", "article.delete", "article.pend", "setting.modify"],
"server": ["server.start"]
}
# Platform Setting Model # Platform Setting Model
PLATFORM_SETTING_MODEL = { PLATFORM_SETTING_MODEL = {