feat: 整合官方 2.7.0 安全修复与本地文件分享
This commit is contained in:
1 parent
b10113e5ab
commit
9e9571b031
42 files changed
+2824
-268
No files matched your search
+13
-3
@@ -1,3 +1,5 @@
|
||||
import time
|
||||
|
||||
from apps.base.models import KeyValue
|
||||
from apps.base.utils import ip_limit
|
||||
from core.database import db_startup_lock
|
||||
@@ -61,7 +63,7 @@ async def ensure_security_settings() -> None:
|
||||
logger.info("已将管理员密码迁移为哈希存储")
|
||||
if security_config.jwt_secret_rotated:
|
||||
logger.info("已生成独立 JWT 签名密钥")
|
||||
await refresh_settings()
|
||||
await refresh_settings(force=True)
|
||||
|
||||
|
||||
def _sync_ip_limits() -> None:
|
||||
@@ -75,11 +77,19 @@ def _sync_ip_limits() -> None:
|
||||
ip_limit["login"].count = settings.loginCount
|
||||
|
||||
|
||||
async def refresh_settings() -> None:
|
||||
CONFIG_CACHE_TTL_SECONDS = 2.0
|
||||
_config_cached_until = 0.0
|
||||
|
||||
|
||||
async def refresh_settings(force: bool = False) -> None:
|
||||
"""从数据库读取最新配置并应用到运行时。"""
|
||||
global _config_cached_until
|
||||
if not force and time.monotonic() < _config_cached_until:
|
||||
return
|
||||
config_record = await KeyValue.filter(key="settings").first()
|
||||
settings.user_config = config_record.value if config_record and config_record.value else {}
|
||||
_sync_ip_limits()
|
||||
_config_cached_until = time.monotonic() + CONFIG_CACHE_TTL_SECONDS
|
||||
|
||||
|
||||
def is_runtime_initialized() -> bool:
|
||||
@@ -118,4 +128,4 @@ async def initialize_system(
|
||||
next_config["jwt_secret"] = generate_jwt_secret()
|
||||
|
||||
await KeyValue.update_or_create(key="settings", defaults={"value": next_config})
|
||||
await refresh_settings()
|
||||
await refresh_settings(force=True)
|
||||
Reference in new issue
Block a user