refactor: route monitor and resource settings through runtime

This commit is contained in:
jxxghp
2026-08-23 01:59:37 +08:00
parent 2c6e8181c2
commit b4e003f098
11 changed files with 68 additions and 47 deletions
+2 -2
View File
@@ -20,8 +20,8 @@ from app.adapters.system.plugin.manifest import (
PluginDependencyManifestError,
load_dependency_manifest,
)
from app.runtime.config import settings
from app.runtime.log import logger
from app.runtime.settings import get_runtime_setting
@dataclass
@@ -52,7 +52,7 @@ class PluginDependencyInstaller:
self._helper = helper
self._installed_plugins_provider = installed_plugins_provider or (lambda: [])
self._plugin_dir = plugin_dir or (
Path(settings.ROOT_PATH) / "app" / "plugins"
Path(get_runtime_setting("ROOT_PATH")) / "app" / "plugins"
)
@staticmethod
+5 -3
View File
@@ -11,8 +11,8 @@ from pathlib import Path
from typing import Optional
from app.adapters.external.market import PluginHelper as _PluginHelper
from app.runtime.config import settings
from app.runtime.log import logger
from app.runtime.settings import get_runtime_setting
@dataclass(frozen=True, slots=True)
@@ -37,7 +37,9 @@ class PluginPackageManager:
@staticmethod
def _plugin_dir(plugin_id: str) -> Path:
"""解析插件运行目录并拒绝越出宿主插件根目录的标识。"""
plugins_root = (Path(settings.ROOT_PATH) / "app" / "plugins").resolve()
plugins_root = (
Path(get_runtime_setting("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):
raise ValueError(f"非法插件ID{plugin_id}")
@@ -47,7 +49,7 @@ class PluginPackageManager:
"""在包变更前创建独立快照,供后续提交或补偿恢复。"""
plugin_dir = self._plugin_dir(plugin_id)
transaction_dir = (
Path(settings.TEMP_PATH)
Path(get_runtime_setting("TEMP_PATH"))
/ "plugin_transactions"
/ f"{plugin_id.lower()}-{uuid.uuid4().hex}"
)
+20 -11
View File
@@ -4,11 +4,16 @@ import sys
from pathlib import Path
from typing import Callable
from app.runtime.config import settings
from app.runtime import config as _runtime_config
from app.runtime.log import logger
from app.adapters.network.http import RequestUtils
from app.foundation.version import compare_version
from app.adapters.system.host import SystemUtils
from app.runtime.settings import get_runtime_setting
# 保留模块级旧 Settings 入口,旧插件和测试可能仍会对其做运行时覆盖;实现读取统一走 runtime 端口。
settings = _runtime_config.settings
ResourceVersionProvider = Callable[[], tuple[str, str]]
@@ -33,11 +38,11 @@ class ResourceHelper:
检测和更新资源包
"""
_base_dir: Path = settings.ROOT_PATH
_base_dir: Path = get_runtime_setting("ROOT_PATH")
_resource_target = Path("app/application/site")
_version_flag = settings.RESOURCE_VERSION_FLAG
_version_flag = get_runtime_setting("RESOURCE_VERSION_FLAG")
_repo = (
f"{settings.GITHUB_PROXY}https://raw.githubusercontent.com/"
f"{get_runtime_setting('GITHUB_PROXY')}https://raw.githubusercontent.com/"
f"jxxghp/MoviePilot-Resources/main/package.{_version_flag}.json"
)
_files_api = (
@@ -48,7 +53,11 @@ class ResourceHelper:
@property
def proxies(self):
"""返回访问 GitHub 资源时应使用的代理配置。"""
return None if settings.GITHUB_PROXY else settings.PROXY
return (
None
if get_runtime_setting("GITHUB_PROXY")
else get_runtime_setting("PROXY")
)
@staticmethod
def _get_python_version_tag() -> str:
@@ -86,7 +95,7 @@ class ResourceHelper:
"""读取 V3 资源清单。"""
response = RequestUtils(
proxies=self.proxies,
headers=settings.GITHUB_HEADERS,
headers=get_runtime_setting("GITHUB_HEADERS"),
timeout=10,
).get_res(self._repo)
return response if response and response.status_code == 200 else None
@@ -104,7 +113,7 @@ class ResourceHelper:
:param indexer_version: 当前已加载的站点索引资源版本;省略时使用组合根注入值
:return: 是否成功安装了需要由上层处理重启的新资源
"""
if not settings.AUTO_UPDATE_RESOURCE:
if not get_runtime_setting("AUTO_UPDATE_RESOURCE"):
return False
if SystemUtils.is_frozen():
return False
@@ -159,8 +168,8 @@ class ResourceHelper:
if need_updates:
# 下载文件信息列表
r = RequestUtils(
proxies=settings.PROXY,
headers=settings.GITHUB_HEADERS,
proxies=get_runtime_setting("PROXY"),
headers=get_runtime_setting("GITHUB_HEADERS"),
timeout=30,
).get_res(self._files_api)
if r and not r.ok:
@@ -186,11 +195,11 @@ class ResourceHelper:
if item.get("download_url"):
logger.info(f"开始更新资源文件:{file_name} ...")
download_url = (
f"{settings.GITHUB_PROXY}{item.get('download_url')}"
f"{get_runtime_setting('GITHUB_PROXY')}{item.get('download_url')}"
)
res = RequestUtils(
proxies=self.proxies,
headers=settings.GITHUB_HEADERS,
headers=get_runtime_setting("GITHUB_HEADERS"),
timeout=180,
).get_res(download_url)
if not res: