diff --git a/backend/app/admin/service/auth_service.py b/backend/app/admin/service/auth_service.py index e938cafa..bba42117 100644 --- a/backend/app/admin/service/auth_service.py +++ b/backend/app/admin/service/auth_service.py @@ -155,7 +155,7 @@ class AuthService: raise errors.NotFoundError(msg=e.msg) except (errors.RequestError, errors.CustomError) as e: if not user: - log.error('登陆错误: 用户密码有误') + log.error(f'登陆错误: {e.msg}') task = BackgroundTask( login_log_service.create, user_uuid=user.uuid if user else uuid4_str(), diff --git a/backend/common/enums.py b/backend/common/enums.py index 33ed2ed3..354e6aa1 100644 --- a/backend/common/enums.py +++ b/backend/common/enums.py @@ -93,7 +93,7 @@ class OperaLogCipherType(IntEnum): aes = 0 md5 = 1 itsdangerous = 2 - plan = 3 + plain = 3 class StatusType(IntEnum): diff --git a/backend/common/i18n.py b/backend/common/i18n.py index bcd46905..ccee328e 100644 --- a/backend/common/i18n.py +++ b/backend/common/i18n.py @@ -54,7 +54,7 @@ class I18n: case 'json': self.locales[lang] = json.loads(f.read()) case 'yaml' | 'yml': - self.locales[lang] = yaml.full_load(f.read()) + self.locales[lang] = yaml.safe_load(f.read()) def t(self, key: str, default: Any | None = None, **kwargs) -> str: """ diff --git a/backend/middleware/access_middleware.py b/backend/middleware/access_middleware.py index 535b852c..4cdc8b7f 100644 --- a/backend/middleware/access_middleware.py +++ b/backend/middleware/access_middleware.py @@ -35,7 +35,7 @@ class AccessMiddleware(BaseHTTPMiddleware): method = request.method if method != 'OPTIONS': - log.debug(f'--> 请求开始[{path if not request.url.query else request.url.path + "/" + request.url.query}]') + log.debug(f'--> 请求开始[{path if not request.url.query else request.url.path + "?" + request.url.query}]') if path.startswith(settings.FASTAPI_API_V1_PATH): PROMETHEUS_REQUEST_IN_PROGRESS_GAUGE.labels(app_name=PROMETHEUS_APP_NAME, method=method, path=path).inc() diff --git a/backend/plugin/core.py b/backend/plugin/core.py index 4ce4a1af..f2623825 100644 --- a/backend/plugin/core.py +++ b/backend/plugin/core.py @@ -176,7 +176,10 @@ def parse_plugin_config() -> tuple[list[dict[str, Any]], list[dict[str, Any]]]: data['plugin']['name'] = plugin plugin_cache_info = run_await(current_redis_client.get)(f'{settings.PLUGIN_REDIS_PREFIX}:{plugin}') if plugin_cache_info: - data['plugin']['enable'] = json.loads(plugin_cache_info)['plugin']['enable'] + try: + data['plugin']['enable'] = json.loads(plugin_cache_info)['plugin']['enable'] + except Exception: + data['plugin']['enable'] = str(StatusType.enable.value) else: data['plugin']['enable'] = str(StatusType.enable.value) @@ -324,5 +327,10 @@ class PluginStatusChecker: log.error('插件状态未初始化或丢失,需重启服务自动修复') raise PluginInjectError('插件状态未初始化或丢失,请联系系统管理员') - if not int(json.loads(plugin_info)['plugin']['enable']): + try: + is_enabled = int(json.loads(plugin_info)['plugin']['enable']) + except Exception: + is_enabled = 0 + + if not is_enabled: raise errors.ServerError(msg=f'插件 {self.plugin} 未启用,请联系系统管理员') diff --git a/backend/utils/request_parse.py b/backend/utils/request_parse.py index 1d68bec2..4939e933 100644 --- a/backend/utils/request_parse.py +++ b/backend/utils/request_parse.py @@ -26,6 +26,9 @@ def get_request_ip(request: Request) -> str: if forwarded: return forwarded.split(',')[0] + if request.client is None: + return '127.0.0.1' + # 忽略 pytest if request.client.host == 'testclient': return '127.0.0.1'