mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
refactor: add dynamic runtime settings compatibility proxy
This commit is contained in:
Vendored
+3
-1
@@ -30,7 +30,7 @@ from importlib.metadata import distributions
|
||||
from requests import Response
|
||||
|
||||
from app.runtime.cache import cached, is_fresh
|
||||
from app.runtime.config import settings
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
from app.adapters.system.package import (
|
||||
PackageInstallRequest,
|
||||
build_package_install_strategies,
|
||||
@@ -52,6 +52,8 @@ from app.adapters.system.host import SystemUtils
|
||||
from app.foundation.url import UrlUtils
|
||||
from version import APP_VERSION
|
||||
|
||||
# 保留模块级可替换入口,代理默认读取组合根的最新 runtime 配置。
|
||||
settings = RuntimeSettingsCompat()
|
||||
PLUGIN_DIR = Path(settings.ROOT_PATH) / "app" / "plugins"
|
||||
LOCAL_REPO_PREFIX = "local://"
|
||||
PLUGIN_SYSTEM_VERSION_FIELD = "system_version"
|
||||
|
||||
Vendored
+5
-1
@@ -6,7 +6,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
from urllib.parse import parse_qs, quote, urlparse, urlsplit
|
||||
|
||||
from app.runtime.cache import cached
|
||||
from app.runtime.config import settings
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
from app.domain.context import MediaInfo, MusicInfo
|
||||
from app.domain.meta.metabase import MetaBase
|
||||
from app.runtime.log import logger
|
||||
@@ -24,6 +24,10 @@ from app.adapters.system.host import SystemUtils
|
||||
from version import APP_VERSION, FRONTEND_VERSION
|
||||
|
||||
|
||||
# 保留旧插件可覆盖的模块级入口,默认通过 runtime 代理动态读取配置。
|
||||
settings = RuntimeSettingsCompat()
|
||||
|
||||
|
||||
_server_report_service: Any = None
|
||||
_server_sharing_service: Any = None
|
||||
|
||||
|
||||
@@ -12,7 +12,11 @@ from typing import Optional
|
||||
|
||||
from app.adapters.external.market import PluginHelper as _PluginHelper
|
||||
from app.runtime.log import logger
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
|
||||
# 保留旧模块级入口,插件本地同步测试和旧扩展仍可能覆盖这些设置。
|
||||
settings = RuntimeSettingsCompat()
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@@ -38,7 +42,7 @@ class PluginPackageManager:
|
||||
def _plugin_dir(plugin_id: str) -> Path:
|
||||
"""解析插件运行目录并拒绝越出宿主插件根目录的标识。"""
|
||||
plugins_root = (
|
||||
Path(get_runtime_setting("ROOT_PATH")) / "app" / "plugins"
|
||||
Path(settings.ROOT_PATH) / "app" / "plugins"
|
||||
).resolve()
|
||||
plugin_dir = (plugins_root / plugin_id.lower()).resolve()
|
||||
if plugin_dir == plugins_root or not plugin_dir.is_relative_to(plugins_root):
|
||||
@@ -49,7 +53,7 @@ class PluginPackageManager:
|
||||
"""在包变更前创建独立快照,供后续提交或补偿恢复。"""
|
||||
plugin_dir = self._plugin_dir(plugin_id)
|
||||
transaction_dir = (
|
||||
Path(get_runtime_setting("TEMP_PATH"))
|
||||
Path(settings.TEMP_PATH)
|
||||
/ "plugin_transactions"
|
||||
/ f"{plugin_id.lower()}-{uuid.uuid4().hex}"
|
||||
)
|
||||
|
||||
@@ -11,6 +11,24 @@ RuntimeSettingProvider = Callable[[str], Any]
|
||||
_provider: RuntimeSettingProvider | None = None
|
||||
|
||||
|
||||
class RuntimeSettingsCompat:
|
||||
"""为旧模块级 Settings 访问提供动态 runtime 配置代理。"""
|
||||
|
||||
def __getattr__(self, key: str) -> Any:
|
||||
"""读取当前组合根配置;未装配时沿用旧 Settings 回退。"""
|
||||
return get_runtime_setting(key)
|
||||
|
||||
def __setattr__(self, key: str, value: Any) -> None:
|
||||
"""把旧模块级覆盖同步到 legacy Settings,保持测试和插件注入语义。"""
|
||||
legacy_settings = importlib.import_module("app.runtime.config").settings
|
||||
setattr(legacy_settings, key, value)
|
||||
|
||||
def __delattr__(self, key: str) -> None:
|
||||
"""删除旧模块级覆盖,使配置对象恢复其原有属性解析。"""
|
||||
legacy_settings = importlib.import_module("app.runtime.config").settings
|
||||
delattr(legacy_settings, key)
|
||||
|
||||
|
||||
def configure_runtime_setting_provider(provider: RuntimeSettingProvider) -> None:
|
||||
"""由启动组合根登记配置读取器,保持适配器只依赖 runtime 端口。"""
|
||||
global _provider
|
||||
|
||||
Reference in New Issue
Block a user