From 23f03822f6bdd57147e7155e41d4bf6599307cd7 Mon Sep 17 00:00:00 2001 From: MangoFanFanw Date: Sat, 6 Jun 2026 10:12:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E7=B4=AF=E7=A7=AF=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=AE=E5=A4=8D=E5=92=8C=E7=BB=86=E8=8A=82?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/nyahome/cli/cli_check.py | 2 +- src/nyahome/cli/cli_config.py | 2 +- src/nyahome/config/manager.py | 10 ++++++++-- src/nyahome/core/core_abc/otp.py | 6 +++--- src/nyahome/core/send_email.py | 4 ++-- src/nyahome/data.py | 2 +- 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b5eb87e..2156260 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ NyaHome 是由 FastAPI 后端、Vue WebUI 实现的在线 AI 文学创作平台 | 功能 | 阶段 | 优先级 | |---------------------------|-----|-----| | **剧本市场** - 剧本分享、聊天室导出为剧本 | 规划中 | 低 | -| **用户功能** - 绑定手机号、接收收集验证码 | 规划中 | 低 | +| **用户功能** - 绑定手机号、接收手机验证码 | 规划中 | 低 | | **用户功能** - 第三方账户 Oauth 登录 | 规划中 | 低 | ## 代码规范 diff --git a/src/nyahome/cli/cli_check.py b/src/nyahome/cli/cli_check.py index d6dd85d..c8463f3 100644 --- a/src/nyahome/cli/cli_check.py +++ b/src/nyahome/cli/cli_check.py @@ -5,7 +5,7 @@ from pathlib import Path from typing import Mapping from nyahome.cli.cli import console -from nyahome.data import db_type_allowlist, db_driver_available +from nyahome.data import db_driver_available, db_type_allowlist class CliWarning: diff --git a/src/nyahome/cli/cli_config.py b/src/nyahome/cli/cli_config.py index bc2e827..15b019d 100644 --- a/src/nyahome/cli/cli_config.py +++ b/src/nyahome/cli/cli_config.py @@ -45,7 +45,7 @@ def set_config_item( """ config_manager.sync_load_config() if len(value) == 1: - value = value[0] + value: str | int | bool = value[0] # type: ignore[no-redef] try: config_manager.set(key, value) except AttributeError: diff --git a/src/nyahome/config/manager.py b/src/nyahome/config/manager.py index 7483f62..c2c51b3 100644 --- a/src/nyahome/config/manager.py +++ b/src/nyahome/config/manager.py @@ -11,7 +11,7 @@ logger = logging.getLogger(__name__) CONFIG_PATH = Path.cwd() / ".nyahome" / "config.json" -T = TypeVar("T") +T = TypeVar("T", str, int, bool, list) class ConfigManager: @@ -88,6 +88,10 @@ class ConfigManager: Args: key: 配置键名 value: 配置键的新值,可以是(且仅支持)字符串、整型以及列表。 + + Raises: + AttributeError: 配置键名错误 + TypeError: 配置键值类型错误 """ try: old_value = self.get(key) @@ -102,7 +106,7 @@ class ConfigManager: case bool(): new_value = bool(value) case list(): - new_value = [x for x in value] + new_value = list(value) case _: raise TypeError(f"不支持 {type(old_value).__name__} 类型的设置项。({key})") setattr(self._config, key, new_value) @@ -114,6 +118,8 @@ class ConfigManager: Args: key: 配置键名 + Raises: + AttributeError: 配置键名错误 """ ci = Config() try: diff --git a/src/nyahome/core/core_abc/otp.py b/src/nyahome/core/core_abc/otp.py index a0d3d4b..acd7407 100644 --- a/src/nyahome/core/core_abc/otp.py +++ b/src/nyahome/core/core_abc/otp.py @@ -42,17 +42,17 @@ class OtpMemoryStore(ABC): async def _cleanup(self) -> None: while True: await asyncio.sleep(60) - logger.debug(f"[{self.type_name}] 开始定时清理过期验证码。") + # logger.debug(f"[{self.type_name}] 开始定时清理过期验证码。") expires = [] count = 0 for address, item in self._store.items(): if item.expire_time < time.time(): - logger.debug(f"[{self.type_name}] 移除过期的 {address}") + # logger.debug(f"[{self.type_name}] 移除过期的 {address}") expires.append(address) count += 1 for address in expires: self._store.pop(address) - logger.debug(f"[{self.type_name}] 清理完成,清理了 {count} 个过期验证码。") + # logger.debug(f"[{self.type_name}] 清理完成,清理了 {count} 个过期验证码。") def verify(self, address: str, user_id: int, verify_code: str) -> bool: item = self._store.get(address) diff --git a/src/nyahome/core/send_email.py b/src/nyahome/core/send_email.py index 3c7945e..3d6afef 100644 --- a/src/nyahome/core/send_email.py +++ b/src/nyahome/core/send_email.py @@ -95,10 +95,10 @@ class EmailSenderQueue(TaskQueue): body=item.body, sender=config_manager.get("smtp_sender"), hostname=config_manager.get("smtp_hostname"), - port=config_manager.get("smtp_port"), + port=config_manager.get("smtp_port", 465), username=config_manager.get("smtp_username"), password=config_manager.get("smtp_password"), - use_tls=config_manager.get("smtp_use_tls"), + use_tls=config_manager.get("smtp_use_tls", True), ) diff --git a/src/nyahome/data.py b/src/nyahome/data.py index f7b0b8c..9ca66d3 100644 --- a/src/nyahome/data.py +++ b/src/nyahome/data.py @@ -3,4 +3,4 @@ db_driver_available = { "mysql": ["pymysql"], "postgresql": ["psycopg"], } -db_type_allowlist = ["sqlite", "mysql", "postgresql"] \ No newline at end of file +db_type_allowlist = ["sqlite", "mysql", "postgresql"]