From 1fbc92bc6d159bf593dfba42891b40081138e96a Mon Sep 17 00:00:00 2001 From: Junyan Qin <1010553892@qq.com> Date: Mon, 14 Oct 2024 21:18:36 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=A6=96=E9=A1=B5=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/api/http/controller/group.py | 2 +- pkg/api/http/controller/groups/system.py | 19 ++++++++++ pkg/api/http/controller/main.py | 2 +- pkg/core/boot.py | 6 +++ pkg/core/bootutils/log.py | 4 +- pkg/utils/constants.py | 2 + web/src/App.vue | 47 ++++++++++++++++++++++-- web/src/pages/Logs.vue | 4 +- web/src/plugins/index.js | 1 + web/src/store/index.js | 14 ++++++- 10 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 pkg/api/http/controller/groups/system.py diff --git a/pkg/api/http/controller/group.py b/pkg/api/http/controller/group.py index b9533567..4f253e05 100644 --- a/pkg/api/http/controller/group.py +++ b/pkg/api/http/controller/group.py @@ -54,7 +54,7 @@ class RouterGroup(abc.ABC): return self.http_status(500, -2, str(e)) new_f = handler_error - new_f.__name__ = f.__name__ + new_f.__name__ = (self.name + rule).replace('/', '__') new_f.__doc__ = f.__doc__ self.quart_app.route(rule, **options)(new_f) diff --git a/pkg/api/http/controller/groups/system.py b/pkg/api/http/controller/groups/system.py new file mode 100644 index 00000000..43b06ddd --- /dev/null +++ b/pkg/api/http/controller/groups/system.py @@ -0,0 +1,19 @@ +import quart + +from .....core import app +from .. import group +from .....utils import constants + + +@group.group_class('system', '/api/v1/system') +class SystemRouterGroup(group.RouterGroup): + + async def initialize(self) -> None: + @self.route('/info', methods=['GET']) + async def _() -> str: + return self.success( + data={ + "version": constants.semantic_version, + "debug": constants.debug_mode + } + ) \ No newline at end of file diff --git a/pkg/api/http/controller/main.py b/pkg/api/http/controller/main.py index 6c7c72f2..76545832 100644 --- a/pkg/api/http/controller/main.py +++ b/pkg/api/http/controller/main.py @@ -5,7 +5,7 @@ import asyncio import quart from ....core import app -from .groups import logs +from .groups import logs, system from . import group diff --git a/pkg/core/boot.py b/pkg/core/boot.py index 1e5f1052..0f0ab3ae 100644 --- a/pkg/core/boot.py +++ b/pkg/core/boot.py @@ -2,10 +2,12 @@ from __future__ import print_function import traceback import asyncio +import os from . import app from ..audit import identifier from . import stage +from ..utils import constants # 引入启动阶段实现以便注册 from .stages import load_config, setup_logger, build_app, migrate, show_notes @@ -25,6 +27,10 @@ async def make_app(loop: asyncio.AbstractEventLoop) -> app.Application: # 生成标识符 identifier.init() + # 确定是否为调试模式 + if "DEBUG" in os.environ and os.environ["DEBUG"] in ["true", "1"]: + constants.debug_mode = True + ap = app.Application() ap.event_loop = loop diff --git a/pkg/core/bootutils/log.py b/pkg/core/bootutils/log.py index ad8252df..36bc51a0 100644 --- a/pkg/core/bootutils/log.py +++ b/pkg/core/bootutils/log.py @@ -5,6 +5,8 @@ import time import colorlog +from ...utils import constants + log_colors_config = { "DEBUG": "green", # cyan white @@ -22,7 +24,7 @@ async def init_logging(extra_handlers: list[logging.Handler] = None) -> logging. level = logging.INFO - if "DEBUG" in os.environ and os.environ["DEBUG"] in ["true", "1"]: + if constants.debug_mode: level = logging.DEBUG log_file_name = "data/logs/qcg-%s.log" % time.strftime( diff --git a/pkg/utils/constants.py b/pkg/utils/constants.py index 74437702..79b470e6 100644 --- a/pkg/utils/constants.py +++ b/pkg/utils/constants.py @@ -1 +1,3 @@ semantic_version = "v3.3.1.1" + +debug_mode = False \ No newline at end of file diff --git a/web/src/App.vue b/web/src/App.vue index 7ba342ba..59f01d97 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -5,7 +5,13 @@ @@ -23,7 +29,7 @@