diff --git a/backend/app/admin/model/opera_log.py b/backend/app/admin/model/opera_log.py index fd114b94..7963d864 100644 --- a/backend/app/admin/model/opera_log.py +++ b/backend/app/admin/model/opera_log.py @@ -16,14 +16,14 @@ class OperaLog(DataClassBase): id: Mapped[id_key] = mapped_column(init=False) trace_id: Mapped[str] = mapped_column(sa.String(32), comment='请求跟踪 ID') username: Mapped[str | None] = mapped_column(sa.String(64), comment='用户名') - method: Mapped[str] = mapped_column(sa.String(32), comment='请求类型') + method: Mapped[str] = mapped_column(sa.String(32), comment='请求方法') title: Mapped[str] = mapped_column(sa.String(256), comment='操作模块') path: Mapped[str] = mapped_column(sa.String(512), comment='请求路径') - ip: Mapped[str] = mapped_column(sa.String(64), comment='IP地址') + ip: Mapped[str] = mapped_column(sa.String(64), comment='IP 地址') country: Mapped[str | None] = mapped_column(sa.String(64), comment='国家') region: Mapped[str | None] = mapped_column(sa.String(64), comment='地区') city: Mapped[str | None] = mapped_column(sa.String(64), comment='城市') - user_agent: Mapped[str | None] = mapped_column(sa.String(512), comment='请求头') + user_agent: Mapped[str | None] = mapped_column(sa.String(512), comment='用户代理') os: Mapped[str | None] = mapped_column(sa.String(64), comment='操作系统') browser: Mapped[str | None] = mapped_column(sa.String(64), comment='浏览器') device: Mapped[str | None] = mapped_column(sa.String(64), comment='设备') 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 1def1a45..2f80243c 100644 --- a/backend/middleware/access_middleware.py +++ b/backend/middleware/access_middleware.py @@ -25,18 +25,18 @@ class AccessMiddleware(BaseHTTPMiddleware): :param call_next: 下一个中间件或路由处理函数 :return: """ - path = request.url.path - method = request.method - - if method != 'OPTIONS': - log.debug(f'--> 请求开始[{path if not request.url.query else request.url.path + "/" + request.url.query}]') - perf_time = time.perf_counter() ctx.perf_time = perf_time start_time = timezone.now() ctx.start_time = start_time + path = request.url.path + method = request.method + + if method != 'OPTIONS': + 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() PROMETHEUS_REQUEST_COUNTER.labels(app_name=PROMETHEUS_APP_NAME, method=method, path=path).inc() diff --git a/backend/plugin/code_generator/utils/gen_template.py b/backend/plugin/code_generator/utils/gen_template.py index eb3ed4ef..0a03f997 100644 --- a/backend/plugin/code_generator/utils/gen_template.py +++ b/backend/plugin/code_generator/utils/gen_template.py @@ -3,6 +3,7 @@ from collections.abc import Sequence from jinja2 import Environment, FileSystemLoader, Template, select_autoescape from pydantic.alias_generators import to_pascal +from backend.common.enums import PrimaryKeyType from backend.core.conf import settings from backend.plugin.code_generator.model import GenBusiness, GenColumn from backend.plugin.code_generator.path_conf import JINJA2_TEMPLATE_DIR @@ -109,7 +110,7 @@ class GenTemplate: 'now': timezone.now(), } - if settings.DATABASE_PK_MODE == 'snowflake': + if PrimaryKeyType.snowflake == settings.DATABASE_PK_MODE: vars_dict['parent_menu_id'] = snowflake.generate() vars_dict['button_ids'] = [snowflake.generate() for _ in range(4)] 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'