mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
refactor: use explicit system config getter
This commit is contained in:
@@ -6,7 +6,7 @@ from typing import Any, Dict, Iterable, Optional
|
||||
|
||||
from app.runtime.events import eventmanager
|
||||
from app.application.agentdata import SubscribePort as SubscribeOper
|
||||
from app.application.configuration import get_configured_system_config as SystemConfigOper
|
||||
from app.application.configuration import get_configured_system_config
|
||||
from app.application.rules import RuleHelper
|
||||
from app.application.rules import RuleParser
|
||||
from app.application.rules import BUILTIN_RULE_SET
|
||||
@@ -252,13 +252,13 @@ async def collect_rule_group_usages(
|
||||
"""收集规则组在全局配置和订阅上的引用情况。"""
|
||||
target_names = set(group_names or [])
|
||||
search_groups = set(
|
||||
SystemConfigOper().get(SystemConfigKey.SearchFilterRuleGroups) or []
|
||||
get_configured_system_config().get(SystemConfigKey.SearchFilterRuleGroups) or []
|
||||
)
|
||||
subscribe_groups = set(
|
||||
SystemConfigOper().get(SystemConfigKey.SubscribeFilterRuleGroups) or []
|
||||
get_configured_system_config().get(SystemConfigKey.SubscribeFilterRuleGroups) or []
|
||||
)
|
||||
best_version_groups = set(
|
||||
SystemConfigOper().get(SystemConfigKey.BestVersionFilterRuleGroups) or []
|
||||
get_configured_system_config().get(SystemConfigKey.BestVersionFilterRuleGroups) or []
|
||||
)
|
||||
|
||||
usage_map = {
|
||||
@@ -428,7 +428,7 @@ async def save_system_config(
|
||||
]
|
||||
normalized_value = normalized_value or None
|
||||
|
||||
success = await SystemConfigOper().async_set(key, normalized_value)
|
||||
success = await get_configured_system_config().async_set(key, normalized_value)
|
||||
if success:
|
||||
await eventmanager.async_send_event(
|
||||
etype=EventType.ConfigChanged,
|
||||
@@ -475,7 +475,7 @@ async def rename_rule_group_references(old_name: str, new_name: str) -> dict:
|
||||
SystemConfigKey.SubscribeFilterRuleGroups,
|
||||
SystemConfigKey.BestVersionFilterRuleGroups,
|
||||
):
|
||||
original = SystemConfigOper().get(config_key) or []
|
||||
original = get_configured_system_config().get(config_key) or []
|
||||
updated = replace_group_name_in_list(original, old_name, new_name)
|
||||
if updated != original:
|
||||
await save_system_config(config_key, updated)
|
||||
@@ -513,7 +513,7 @@ async def remove_rule_group_references(group_name: str) -> dict:
|
||||
SystemConfigKey.SubscribeFilterRuleGroups,
|
||||
SystemConfigKey.BestVersionFilterRuleGroups,
|
||||
):
|
||||
original = SystemConfigOper().get(config_key) or []
|
||||
original = get_configured_system_config().get(config_key) or []
|
||||
updated = [value for value in original if value != group_name]
|
||||
if updated != original:
|
||||
await save_system_config(config_key, updated)
|
||||
|
||||
@@ -11,7 +11,7 @@ from app.runtime.settings import RuntimeSettingsCompat
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.application.plugin.runtime import get_plugin_manager
|
||||
from app.application.plugin.install import PluginInstallCommand
|
||||
from app.application.configuration import get_configured_system_config as SystemConfigOper
|
||||
from app.application.configuration import get_configured_system_config
|
||||
from app.adapters.external.server import MoviePilotServerHelper
|
||||
from app.adapters.external.market import PluginHelper
|
||||
from app.adapters.system.plugin.package import PluginPackageManager
|
||||
@@ -327,7 +327,7 @@ async def install_plugin_runtime(
|
||||
|
||||
async def save_installed_plugins(plugin_ids: list[str]) -> object:
|
||||
"""保存智能体安装用例确认后的插件列表。"""
|
||||
return await SystemConfigOper().async_set(
|
||||
return await get_configured_system_config().async_set(
|
||||
SystemConfigKey.UserInstalledPlugins,
|
||||
plugin_ids,
|
||||
)
|
||||
@@ -377,7 +377,7 @@ async def install_plugin_runtime(
|
||||
return result
|
||||
|
||||
result = await PluginInstallCommand(
|
||||
installed_plugins_reader=lambda: SystemConfigOper().get(
|
||||
installed_plugins_reader=lambda: get_configured_system_config().get(
|
||||
SystemConfigKey.UserInstalledPlugins
|
||||
) or [],
|
||||
installed_plugins_writer=save_installed_plugins,
|
||||
@@ -422,7 +422,7 @@ async def uninstall_plugin_runtime(plugin_id: str) -> dict[str, Any]:
|
||||
instance_ids = "、".join(item.instance_id for item in source_instances)
|
||||
raise ValueError(f"请先卸载该插件的分身:{instance_ids}")
|
||||
|
||||
config_oper = SystemConfigOper()
|
||||
config_oper = get_configured_system_config()
|
||||
install_plugins = config_oper.get(SystemConfigKey.UserInstalledPlugins) or []
|
||||
if plugin_id in install_plugins:
|
||||
install_plugins = [
|
||||
|
||||
@@ -7,7 +7,7 @@ from pydantic import BaseModel
|
||||
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.application.configuration import get_configured_system_config as SystemConfigOper
|
||||
from app.application.configuration import get_configured_system_config
|
||||
from app.runtime.log import logger
|
||||
from app.schemas.types import SystemConfigKey
|
||||
|
||||
@@ -39,7 +39,7 @@ class QueryCustomIdentifiersTool(MoviePilotTool):
|
||||
@staticmethod
|
||||
def _load_custom_identifiers():
|
||||
"""从内存配置缓存中读取自定义识别词。"""
|
||||
return SystemConfigOper().get(SystemConfigKey.CustomIdentifiers)
|
||||
return get_configured_system_config().get(SystemConfigKey.CustomIdentifiers)
|
||||
|
||||
async def run(self, **kwargs) -> str:
|
||||
logger.info(f"执行工具: {self.name}")
|
||||
|
||||
@@ -7,7 +7,7 @@ from pydantic import BaseModel
|
||||
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.application.configuration import get_configured_system_config as SystemConfigOper
|
||||
from app.application.configuration import get_configured_system_config
|
||||
from app.runtime.log import logger
|
||||
from app.schemas.types import SystemConfigKey
|
||||
|
||||
@@ -34,7 +34,7 @@ class QueryDownloadersTool(MoviePilotTool):
|
||||
@staticmethod
|
||||
def _load_downloaders_config():
|
||||
"""从内存配置缓存中读取下载器配置。"""
|
||||
return SystemConfigOper().get(SystemConfigKey.Downloaders)
|
||||
return get_configured_system_config().get(SystemConfigKey.Downloaders)
|
||||
|
||||
@staticmethod
|
||||
def _sanitize_downloaders_config(downloaders_config: list) -> list:
|
||||
|
||||
@@ -17,7 +17,7 @@ from app.agent.tools.impl._system_setting_utils import (
|
||||
)
|
||||
from app.application.configuration import (
|
||||
SystemConfigReader,
|
||||
get_configured_system_config as SystemConfigOper,
|
||||
get_configured_system_config,
|
||||
get_runtime_settings,
|
||||
)
|
||||
from app.runtime.log import logger
|
||||
@@ -103,7 +103,7 @@ class QuerySystemSettingsTool(MoviePilotTool):
|
||||
|
||||
def _get_system_config(self) -> SystemConfigReader:
|
||||
"""返回显式注入端口,旧构造形态则延迟读取组合根服务。"""
|
||||
return self._system_config or SystemConfigOper()
|
||||
return self._system_config or get_configured_system_config()
|
||||
|
||||
async def _run_confirmed(self, **kwargs) -> str:
|
||||
"""仅供宿主在消费有效确认后执行一次未脱敏读取。"""
|
||||
|
||||
@@ -8,7 +8,7 @@ from pydantic import BaseModel, Field
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.chain.search import SearchChain
|
||||
from app.application.configuration import get_configured_system_config as SystemConfigOper
|
||||
from app.application.configuration import get_configured_system_config
|
||||
from app.application.site.sites import SitesHelper # pylint: disable=import-error,no-name-in-module
|
||||
from app.runtime.log import logger
|
||||
from app.schemas.types import MediaSource, MediaType, SystemConfigKey
|
||||
@@ -63,7 +63,7 @@ class SearchTorrentsTool(MoviePilotTool):
|
||||
@staticmethod
|
||||
def _load_configured_sites() -> List[int]:
|
||||
"""同步读取默认搜索站点列表。"""
|
||||
return SystemConfigOper().get(SystemConfigKey.IndexerSites) or []
|
||||
return get_configured_system_config().get(SystemConfigKey.IndexerSites) or []
|
||||
|
||||
async def run(self, media_source: MediaSource, media_id: str,
|
||||
media_type: Optional[str] = None, area: Optional[str] = None,
|
||||
|
||||
@@ -8,7 +8,7 @@ from pydantic import BaseModel, Field
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.agent.tools.tags import ToolTag
|
||||
from app.domain.metainfo import clear_rust_parse_options_cache
|
||||
from app.application.configuration import get_configured_system_config as SystemConfigOper
|
||||
from app.application.configuration import get_configured_system_config
|
||||
from app.runtime.log import logger
|
||||
from app.schemas.types import SystemConfigKey
|
||||
|
||||
@@ -80,7 +80,7 @@ class UpdateCustomIdentifiersTool(MoviePilotTool):
|
||||
# 过滤空字符串
|
||||
identifiers = [i for i in identifiers if i is not None]
|
||||
|
||||
system_config_oper = SystemConfigOper()
|
||||
system_config_oper = get_configured_system_config()
|
||||
|
||||
# 保存
|
||||
value = identifiers if identifiers else None
|
||||
|
||||
@@ -19,7 +19,7 @@ from app.agent.tools.impl._system_setting_utils import (
|
||||
from app.runtime.events import eventmanager
|
||||
from app.application.configuration import (
|
||||
SystemConfigService,
|
||||
get_configured_system_config as SystemConfigOper,
|
||||
get_configured_system_config,
|
||||
get_runtime_settings,
|
||||
)
|
||||
from app.application.plugin.runtime import plugin_system_config_mutation
|
||||
@@ -109,7 +109,7 @@ class UpdateSystemSettingsTool(MoviePilotTool):
|
||||
|
||||
def _get_system_config(self) -> SystemConfigService:
|
||||
"""返回显式注入服务,旧构造形态则延迟读取组合根服务。"""
|
||||
return self._system_config or SystemConfigOper()
|
||||
return self._system_config or get_configured_system_config()
|
||||
|
||||
def get_tool_message(self, **kwargs) -> Optional[str]:
|
||||
"""根据更新参数生成友好的提示消息。"""
|
||||
|
||||
Reference in New Issue
Block a user