diff --git a/app.py b/app.py index 9fc9323..5dfc7f0 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,6 @@ import os -from flask import Flask, jsonify +from flask import Flask from bcrypt import checkpw, gensalt, hashpw from sqlalchemy import create_engine @@ -21,9 +21,9 @@ PLATFORM_ROOT_PASSWORD = os.getenv("PLATFORM_ROOT_PASSWORD", None) # env checker 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") -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") if len(errmsg): print(f"Env check failed: {errmsg}") @@ -71,4 +71,4 @@ def index(): # app run if __name__ == "__main__": - app.run(host="0.0.0.0", port=5000, debug=False) \ No newline at end of file + app.run(host="0.0.0.0", port=5000, debug=False) diff --git a/blueprints/admin.py b/blueprints/admin.py index 4993b92..4b5ba56 100644 --- a/blueprints/admin.py +++ b/blueprints/admin.py @@ -235,7 +235,7 @@ def setting_get(): @admin.route("/setting", methods=["POST"]) @role_required(["setting.edit"]) def setting_edit(): - opuser = g.opuser + opuser = g.opuser.user req = request.json d = None diff --git a/blueprints/log.py b/blueprints/log.py index 18b4558..b2e1953 100644 --- a/blueprints/log.py +++ b/blueprints/log.py @@ -12,7 +12,7 @@ log = Blueprint('log', __name__) def listlog(): # variables 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 rst = int(request.args.get("start")) count = int(request.args.get("count")) diff --git a/settings.json b/settings.json index 6171670..6071926 100644 --- a/settings.json +++ b/settings.json @@ -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"]} \ No newline at end of file +{"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"]} \ No newline at end of file diff --git a/utils/dbhelper.py b/utils/dbhelper.py index 7ddb00a..6926f1b 100644 --- a/utils/dbhelper.py +++ b/utils/dbhelper.py @@ -11,12 +11,12 @@ class db: _engine = None @classmethod - def __init__(self, engine): - self._engine = engine + def __init__(cls, engine): + cls._engine = engine @classmethod - def getsession(self): - Session = sessionmaker(bind=self._engine) + def getsession(cls): + Session = sessionmaker(bind=cls._engine) return Session() # 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 # checker 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 start = int(start) count = int(count) diff --git a/utils/ighelper.py b/utils/ighelper.py index b2725f2..c4971b2 100644 --- a/utils/ighelper.py +++ b/utils/ighelper.py @@ -1,2 +1,2 @@ def ighelper(): - pass \ No newline at end of file + pass diff --git a/utils/logger.py b/utils/logger.py index cc1f9cf..3a8562d 100644 --- a/utils/logger.py +++ b/utils/logger.py @@ -1,21 +1,16 @@ from utils import pgclass 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): table = pgclass.SQLlog flag = False - # new post & del post - if type in EVENT_TYPE_GENERAL: - flag = True - log = table(source = "general", message = message) - elif type in EVENT_TYPE_ADMIN: - flag = True - log = table(source = "admin", message = message) - elif type in EVENT_TYPE_SERVER: - flag = True - log = table(source = "server", message = message) + for etl in EVENT_TYPE: + if type in EVENT_TYPE[etl]: + flag = True + log = table(source = etl, message = message) + break # session.add if flag: diff --git a/utils/pgclass.py b/utils/pgclass.py index 74329c9..59f5883 100644 --- a/utils/pgclass.py +++ b/utils/pgclass.py @@ -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 Base = declarative_base() diff --git a/utils/platform_consts.py b/utils/platform_consts.py index 4f68ab0..a2337f1 100644 --- a/utils/platform_consts.py +++ b/utils/platform_consts.py @@ -3,9 +3,11 @@ PLIST = ["article.read", "article.pend", "article.del", "setting.edit"] # no per PLIST_ROOT = PLIST + ["usermgr"] # event type -EVENT_TYPE_GENERAL = ["newpost", "delpost"] -EVENT_TYPE_ADMIN = ["login", "user.create", "user.delete", "article.delete", "article.pend", "setting.modify"] -EVENT_TYPE_SERVER = ["server.start"] +EVENT_TYPE = { + "general": ["newpost", "delpost"], + "admin": ["login", "user.create", "user.delete", "article.delete", "article.pend", "setting.modify"], + "server": ["server.start"] +} # Platform Setting Model PLATFORM_SETTING_MODEL = {