mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-29 03:56:43 +08:00
refactor: inject runtime settings compatibility service
This commit is contained in:
@@ -386,6 +386,9 @@ def configure_runtime_settings(service: RuntimeSettingsService) -> None:
|
||||
"""由组合根登记管理 API 使用的部署设置服务。"""
|
||||
global _runtime_settings_service
|
||||
_runtime_settings_service = service
|
||||
from app.runtime.settings import configure_runtime_settings_compat
|
||||
|
||||
configure_runtime_settings_compat(service)
|
||||
|
||||
|
||||
def get_runtime_settings() -> RuntimeSettingsService:
|
||||
|
||||
+17
-19
@@ -9,6 +9,7 @@ from typing import Any
|
||||
|
||||
RuntimeSettingProvider = Callable[[str], Any]
|
||||
_provider: RuntimeSettingProvider | None = None
|
||||
_runtime_settings_service: Any | None = None
|
||||
# 测试和插件可能临时替换某个模块上的 importlib.import_module;保存原始函数,
|
||||
# 让兼容代理的 legacy Settings 解析不受这类局部替身影响。
|
||||
_import_module = importlib.import_module
|
||||
@@ -42,32 +43,29 @@ class RuntimeSettingsCompat:
|
||||
**kwargs: Any,
|
||||
) -> dict[str, Any]:
|
||||
"""导出当前配置快照,保留旧 Settings 的序列化入口。"""
|
||||
try:
|
||||
from app.application.configuration import get_runtime_settings
|
||||
|
||||
return get_runtime_settings().snapshot(include=include, exclude=exclude)
|
||||
except RuntimeError:
|
||||
return self._legacy_settings().model_dump(
|
||||
include=include, exclude=exclude, **kwargs
|
||||
)
|
||||
if _runtime_settings_service is not None:
|
||||
return _runtime_settings_service.snapshot(include=include, exclude=exclude)
|
||||
return self._legacy_settings().model_dump(
|
||||
include=include, exclude=exclude, **kwargs
|
||||
)
|
||||
|
||||
def update_setting(self, key: str, value: Any) -> tuple[Any, str]:
|
||||
"""更新单项配置,兼容插件对模块级 Settings 的公开调用。"""
|
||||
try:
|
||||
from app.application.configuration import get_runtime_settings
|
||||
|
||||
return get_runtime_settings().update(key, value)
|
||||
except RuntimeError:
|
||||
return self._legacy_settings().update_setting(key, value)
|
||||
if _runtime_settings_service is not None:
|
||||
return _runtime_settings_service.update(key, value)
|
||||
return self._legacy_settings().update_setting(key, value)
|
||||
|
||||
def update_settings(self, env: dict[str, Any]) -> dict[str, tuple[Any, str]]:
|
||||
"""批量更新配置,兼容旧 Settings 的管理接口。"""
|
||||
try:
|
||||
from app.application.configuration import get_runtime_settings
|
||||
if _runtime_settings_service is not None:
|
||||
return _runtime_settings_service.update_many(env)
|
||||
return self._legacy_settings().update_settings(env=env)
|
||||
|
||||
return get_runtime_settings().update_many(env)
|
||||
except RuntimeError:
|
||||
return self._legacy_settings().update_settings(env=env)
|
||||
|
||||
def configure_runtime_settings_compat(service: Any) -> None:
|
||||
"""由应用组合根注入可变配置服务,避免低层代理反向导入应用层。"""
|
||||
global _runtime_settings_service
|
||||
_runtime_settings_service = service
|
||||
|
||||
|
||||
def configure_runtime_setting_provider(provider: RuntimeSettingProvider) -> None:
|
||||
|
||||
+5
-4
@@ -13,8 +13,8 @@
|
||||
"runtime_to_db": [],
|
||||
"workflow_to_db": []
|
||||
},
|
||||
"edge_count": 6431,
|
||||
"edge_sha256": "7856a4d76df46e0fec9fae87c9b1167c7e01df507d02308b3b1fd4f2135eb41c",
|
||||
"edge_count": 6432,
|
||||
"edge_sha256": "96bead9b5bbbf10d49a5be50d7d9dc33f47e23010ef28d02a17aebfc3b250e4f",
|
||||
"edges": [
|
||||
"app -> app.runtime",
|
||||
"app -> app.runtime.compat",
|
||||
@@ -404,8 +404,6 @@
|
||||
"app.agent.skills.registry -> app.agent",
|
||||
"app.agent.skills.registry -> app.agent.skills",
|
||||
"app.agent.skills.registry -> app.agent.skills.metadata",
|
||||
"app.agent.skills.registry -> app.application",
|
||||
"app.agent.skills.registry -> app.application.configuration",
|
||||
"app.agent.skills.registry -> app.foundation",
|
||||
"app.agent.skills.registry -> app.foundation.singleton",
|
||||
"app.agent.skills.registry -> app.foundation.url",
|
||||
@@ -2468,6 +2466,8 @@
|
||||
"app.application.chain.durable_events -> app.schemas.file",
|
||||
"app.application.chain.durable_events -> app.schemas.transfer",
|
||||
"app.application.chain.durable_events -> app.schemas.types",
|
||||
"app.application.configuration -> app.runtime",
|
||||
"app.application.configuration -> app.runtime.settings",
|
||||
"app.application.configuration -> app.schemas",
|
||||
"app.application.configuration -> app.schemas.types",
|
||||
"app.application.dashboard -> app.schemas",
|
||||
@@ -3667,6 +3667,7 @@
|
||||
"app.db.oper.user -> app.db.models.user",
|
||||
"app.db.oper.userconfig -> app.db",
|
||||
"app.db.oper.userconfig -> app.db.base",
|
||||
"app.db.oper.userconfig -> app.db.decorators",
|
||||
"app.db.oper.userconfig -> app.db.models",
|
||||
"app.db.oper.userconfig -> app.db.models.userconfig",
|
||||
"app.db.oper.userconfig -> app.foundation",
|
||||
|
||||
Reference in New Issue
Block a user