mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-29 03:56:43 +08:00
refactor: centralize startup system configuration
This commit is contained in:
@@ -40,6 +40,7 @@ from app.application.configuration import (
|
||||
RuntimeConfiguration,
|
||||
RuntimeSettingsService,
|
||||
SystemConfigService,
|
||||
get_configured_system_config,
|
||||
TransferRetryConfig,
|
||||
configure_runtime_configuration,
|
||||
configure_runtime_settings,
|
||||
@@ -185,7 +186,7 @@ def _build_chain_runtime_context() -> ChainRuntimeContext:
|
||||
|
||||
def configure_runtime_data_providers() -> None:
|
||||
"""在启动组合层装配运行时和外部服务所需的数据库读取能力。"""
|
||||
configure_service_config_reader(lambda key: SystemConfigOper().get(key))
|
||||
configure_service_config_reader(lambda key: get_configured_system_config().get(key))
|
||||
configure_module_runtime(lambda: ModuleManager())
|
||||
configure_plugin_runtime(lambda: PluginManager())
|
||||
configure_service_directory(
|
||||
@@ -196,9 +197,9 @@ def configure_runtime_data_providers() -> None:
|
||||
)
|
||||
configure_server_application_services(
|
||||
report_service=ServerReportService(
|
||||
config_reader=lambda key: SystemConfigOper().get(key),
|
||||
config_writer=lambda key, value: SystemConfigOper().set(key, value),
|
||||
installed_plugins_provider=lambda: SystemConfigOper().get(
|
||||
config_reader=lambda key: get_configured_system_config().get(key),
|
||||
config_writer=lambda key, value: get_configured_system_config().set(key, value),
|
||||
installed_plugins_provider=lambda: get_configured_system_config().get(
|
||||
SystemConfigKey.UserInstalledPlugins
|
||||
) or [],
|
||||
subscribes_provider=lambda: SubscribeOper().list(),
|
||||
@@ -406,7 +407,7 @@ def user_auth():
|
||||
sites_helper = SitesHelper()
|
||||
if sites_helper.auth_level >= 2:
|
||||
return
|
||||
auth_conf = SystemConfigOper().get(SystemConfigKey.UserSiteAuthParams)
|
||||
auth_conf = get_configured_system_config().get(SystemConfigKey.UserSiteAuthParams)
|
||||
status, msg = sites_helper.check_user(**auth_conf) if auth_conf else sites_helper.check_user()
|
||||
if status:
|
||||
logger.info(f"{msg} 用户认证成功")
|
||||
@@ -565,6 +566,8 @@ async def init_modules() -> HostRuntime:
|
||||
)
|
||||
configure_runtime_configuration(host_runtime.configuration)
|
||||
configure_runtime_settings(host_runtime.settings)
|
||||
# 先发布系统配置服务,后续启动组合步骤统一复用同一配置端口。
|
||||
configure_system_config(SystemConfigService(repository=SystemConfigOper()))
|
||||
# 旧 app.api.data 导入只保留 ABI 转发,正式 API 依赖全部读取 HostRuntime。
|
||||
configure_api_data_runtime(api_data)
|
||||
configure_runtime_data_providers()
|
||||
@@ -583,7 +586,6 @@ async def init_modules() -> HostRuntime:
|
||||
),
|
||||
user=lambda: UserOper(),
|
||||
)
|
||||
configure_system_config(SystemConfigService(repository=SystemConfigOper()))
|
||||
configure_outbox_dispatcher(_build_outbox_dispatcher)
|
||||
configure_transfer_retry_config(
|
||||
lambda: TransferRetryConfig(
|
||||
@@ -600,7 +602,7 @@ async def init_modules() -> HostRuntime:
|
||||
configure_auth_service(
|
||||
AuthService(
|
||||
users=UserOper(),
|
||||
config=SystemConfigOper(),
|
||||
config=get_configured_system_config(),
|
||||
passkeys=PassKeyOper(),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ from app.adapters.system.plugin.manifest import dependency_manifest_status
|
||||
from app.adapters.system.plugin.package import PluginPackageManager
|
||||
from app.adapters.system.host import SystemUtils
|
||||
from app.db.oper.plugindata import PluginDataOper
|
||||
from app.db.oper.systemconfig import SystemConfigOper
|
||||
from app.application.configuration import get_configured_system_config
|
||||
from app.db.session import SessionFactory
|
||||
from app.db.uow import SqlAlchemyUnitOfWork
|
||||
from app.runtime.log import logger
|
||||
@@ -52,7 +52,7 @@ from app.schemas.types import SystemConfigKey
|
||||
|
||||
async def _async_write_plugin_config(key, value):
|
||||
"""通过数据库操作器异步保存插件运行时配置。"""
|
||||
return await SystemConfigOper().async_set(key, value)
|
||||
return await get_configured_system_config().async_set(key, value)
|
||||
|
||||
|
||||
def _delete_plugin_data(plugin_id: str) -> None:
|
||||
@@ -88,7 +88,7 @@ def configure_plugin_services() -> None:
|
||||
configure_plugin_install_reporter(MoviePilotServerHelper.install_plugin_reg)
|
||||
configure_site_auth_level_provider(lambda: SitesHelper().auth_level)
|
||||
configure_installed_plugins_provider(
|
||||
lambda: SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
|
||||
lambda: get_configured_system_config().get(SystemConfigKey.UserInstalledPlugins) or []
|
||||
)
|
||||
configure_plugin_catalog_factory(_build_plugin_catalog)
|
||||
configure_plugin_system(PluginSystemServices(
|
||||
@@ -96,7 +96,7 @@ def configure_plugin_services() -> None:
|
||||
package=PluginPackageManager(plugin_helper),
|
||||
dependency=PluginDependencyInstaller(
|
||||
plugin_helper,
|
||||
installed_plugins_provider=lambda: SystemConfigOper().get(
|
||||
installed_plugins_provider=lambda: get_configured_system_config().get(
|
||||
SystemConfigKey.UserInstalledPlugins
|
||||
) or [],
|
||||
plugin_dir=Path(settings.ROOT_PATH) / "app" / "plugins",
|
||||
@@ -109,10 +109,10 @@ def configure_plugin_services() -> None:
|
||||
frozen=SystemUtils.is_frozen,
|
||||
))
|
||||
configure_plugin_storage(PluginStorage(
|
||||
read=lambda key: SystemConfigOper().get(key),
|
||||
write=lambda key, value: SystemConfigOper().set(key, value),
|
||||
read=lambda key: get_configured_system_config().get(key),
|
||||
write=lambda key, value: get_configured_system_config().set(key, value),
|
||||
async_write=_async_write_plugin_config,
|
||||
delete=lambda key: SystemConfigOper().delete(key),
|
||||
delete=lambda key: get_configured_system_config().delete(key),
|
||||
delete_data=_delete_plugin_data,
|
||||
))
|
||||
|
||||
@@ -123,7 +123,7 @@ def _build_plugin_catalog(manager: PluginManager) -> PluginCatalogService:
|
||||
return PluginCatalogService(
|
||||
market_loader=client.get_plugins,
|
||||
async_market_loader=client.async_get_plugins,
|
||||
installed_plugins_provider=lambda: SystemConfigOper().get(
|
||||
installed_plugins_provider=lambda: get_configured_system_config().get(
|
||||
SystemConfigKey.UserInstalledPlugins
|
||||
) or [],
|
||||
plugin_mapper=manager._process_plugin_info,
|
||||
|
||||
@@ -148,60 +148,8 @@
|
||||
{
|
||||
"file": "app/startup/modules_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/modules_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/modules_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/modules_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/modules_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/modules_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/modules_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/plugins_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/plugins_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/plugins_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/plugins_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/plugins_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/plugins_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
},
|
||||
{
|
||||
"file": "app/startup/plugins_initializer.py",
|
||||
"name": "SystemConfigOper"
|
||||
}
|
||||
],
|
||||
"count": 14
|
||||
"count": 1
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@
|
||||
"workflow_to_db": []
|
||||
},
|
||||
"edge_count": 6404,
|
||||
"edge_sha256": "08caab762b3882534d0cdf43ea4e0fcaf28c580f5e04537346f742b212854123",
|
||||
"edge_sha256": "850e490b866ed8eeee03515e39a3821c3078f934c622a60d9db5e279bab1bfbb",
|
||||
"edges": [
|
||||
"app -> app.runtime",
|
||||
"app -> app.runtime.compat",
|
||||
@@ -6176,6 +6176,7 @@
|
||||
"app.startup.plugins_initializer -> app.adapters.system.plugin.manifest",
|
||||
"app.startup.plugins_initializer -> app.adapters.system.plugin.package",
|
||||
"app.startup.plugins_initializer -> app.application",
|
||||
"app.startup.plugins_initializer -> app.application.configuration",
|
||||
"app.startup.plugins_initializer -> app.application.plugin",
|
||||
"app.startup.plugins_initializer -> app.application.plugin.catalog",
|
||||
"app.startup.plugins_initializer -> app.application.plugin.data",
|
||||
@@ -6184,7 +6185,6 @@
|
||||
"app.startup.plugins_initializer -> app.db",
|
||||
"app.startup.plugins_initializer -> app.db.oper",
|
||||
"app.startup.plugins_initializer -> app.db.oper.plugindata",
|
||||
"app.startup.plugins_initializer -> app.db.oper.systemconfig",
|
||||
"app.startup.plugins_initializer -> app.db.session",
|
||||
"app.startup.plugins_initializer -> app.db.uow",
|
||||
"app.startup.plugins_initializer -> app.foundation",
|
||||
|
||||
Reference in New Issue
Block a user