mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
feat:插件市场支持强制刷新
This commit is contained in:
@@ -137,7 +137,7 @@ def register_plugin(plugin_id: str):
|
|||||||
|
|
||||||
@router.get("/", summary="所有插件", response_model=List[schemas.Plugin])
|
@router.get("/", summary="所有插件", response_model=List[schemas.Plugin])
|
||||||
def all_plugins(_: schemas.TokenPayload = Depends(get_current_active_superuser),
|
def all_plugins(_: schemas.TokenPayload = Depends(get_current_active_superuser),
|
||||||
state: Optional[str] = "all") -> List[schemas.Plugin]:
|
state: Optional[str] = "all", force: bool = False) -> List[schemas.Plugin]:
|
||||||
"""
|
"""
|
||||||
查询所有插件清单,包括本地插件和在线插件,插件状态:installed, market, all
|
查询所有插件清单,包括本地插件和在线插件,插件状态:installed, market, all
|
||||||
"""
|
"""
|
||||||
@@ -151,7 +151,7 @@ def all_plugins(_: schemas.TokenPayload = Depends(get_current_active_superuser),
|
|||||||
# 未安装的本地插件
|
# 未安装的本地插件
|
||||||
not_installed_plugins = [plugin for plugin in local_plugins if not plugin.installed]
|
not_installed_plugins = [plugin for plugin in local_plugins if not plugin.installed]
|
||||||
# 在线插件
|
# 在线插件
|
||||||
online_plugins = PluginManager().get_online_plugins()
|
online_plugins = PluginManager().get_online_plugins(force)
|
||||||
if not online_plugins:
|
if not online_plugins:
|
||||||
# 没有获取在线插件
|
# 没有获取在线插件
|
||||||
if state == "market":
|
if state == "market":
|
||||||
|
|||||||
+8
-5
@@ -754,7 +754,7 @@ class PluginManager(metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
return list(self._running_plugins.keys())
|
return list(self._running_plugins.keys())
|
||||||
|
|
||||||
def get_online_plugins(self) -> List[schemas.Plugin]:
|
def get_online_plugins(self, force: bool = False) -> List[schemas.Plugin]:
|
||||||
"""
|
"""
|
||||||
获取所有在线插件信息
|
获取所有在线插件信息
|
||||||
"""
|
"""
|
||||||
@@ -775,12 +775,13 @@ class PluginManager(metaclass=Singleton):
|
|||||||
if not m:
|
if not m:
|
||||||
continue
|
continue
|
||||||
# 提交任务获取 v1 版本插件,存储 future 到 version 的映射
|
# 提交任务获取 v1 版本插件,存储 future 到 version 的映射
|
||||||
base_future = executor.submit(self.get_plugins_from_market, m, None)
|
base_future = executor.submit(self.get_plugins_from_market, m, None, force)
|
||||||
futures_to_version[base_future] = "base_version"
|
futures_to_version[base_future] = "base_version"
|
||||||
|
|
||||||
# 提交任务获取高版本插件(如 v2、v3),存储 future 到 version 的映射
|
# 提交任务获取高版本插件(如 v2、v3),存储 future 到 version 的映射
|
||||||
if settings.VERSION_FLAG:
|
if settings.VERSION_FLAG:
|
||||||
higher_version_future = executor.submit(self.get_plugins_from_market, m, settings.VERSION_FLAG)
|
higher_version_future = executor.submit(self.get_plugins_from_market, m,
|
||||||
|
settings.VERSION_FLAG, force)
|
||||||
futures_to_version[higher_version_future] = "higher_version"
|
futures_to_version[higher_version_future] = "higher_version"
|
||||||
|
|
||||||
# 按照完成顺序处理结果
|
# 按照完成顺序处理结果
|
||||||
@@ -908,11 +909,13 @@ class PluginManager(metaclass=Singleton):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def get_plugins_from_market(self, market: str,
|
def get_plugins_from_market(self, market: str,
|
||||||
package_version: Optional[str] = None) -> Optional[List[schemas.Plugin]]:
|
package_version: Optional[str] = None,
|
||||||
|
force: bool = False) -> Optional[List[schemas.Plugin]]:
|
||||||
"""
|
"""
|
||||||
从指定的市场获取插件信息
|
从指定的市场获取插件信息
|
||||||
:param market: 市场的 URL 或标识
|
:param market: 市场的 URL 或标识
|
||||||
:param package_version: 首选插件版本 (如 "v2", "v3"),如果不指定则获取 v1 版本
|
:param package_version: 首选插件版本 (如 "v2", "v3"),如果不指定则获取 v1 版本
|
||||||
|
:param force: 是否强制刷新(忽略缓存)
|
||||||
:return: 返回插件的列表,若获取失败返回 []
|
:return: 返回插件的列表,若获取失败返回 []
|
||||||
"""
|
"""
|
||||||
if not market:
|
if not market:
|
||||||
@@ -920,7 +923,7 @@ class PluginManager(metaclass=Singleton):
|
|||||||
# 已安装插件
|
# 已安装插件
|
||||||
installed_apps = SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
|
installed_apps = SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
|
||||||
# 获取在线插件
|
# 获取在线插件
|
||||||
online_plugins = PluginHelper().get_plugins(market, package_version)
|
online_plugins = PluginHelper().get_plugins(market, package_version, force)
|
||||||
if online_plugins is None:
|
if online_plugins is None:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"获取{package_version if package_version else ''}插件库失败:{market},请检查 GitHub 网络连接")
|
f"获取{package_version if package_version else ''}插件库失败:{market},请检查 GitHub 网络连接")
|
||||||
|
|||||||
+25
-2
@@ -41,12 +41,35 @@ class PluginHelper(metaclass=Singleton):
|
|||||||
if self.install_report():
|
if self.install_report():
|
||||||
self.systemconfig.set(SystemConfigKey.PluginInstallReport, "1")
|
self.systemconfig.set(SystemConfigKey.PluginInstallReport, "1")
|
||||||
|
|
||||||
@cached(maxsize=64, ttl=1800)
|
def get_plugins(self, repo_url: str, package_version: Optional[str] = None,
|
||||||
def get_plugins(self, repo_url: str, package_version: Optional[str] = None) -> Optional[Dict[str, dict]]:
|
force: bool = False) -> Optional[Dict[str, dict]]:
|
||||||
"""
|
"""
|
||||||
获取Github所有最新插件列表
|
获取Github所有最新插件列表
|
||||||
:param repo_url: Github仓库地址
|
:param repo_url: Github仓库地址
|
||||||
:param package_version: 首选插件版本 (如 "v2", "v3"),如果不指定则获取 v1 版本
|
:param package_version: 首选插件版本 (如 "v2", "v3"),如果不指定则获取 v1 版本
|
||||||
|
:param force: 是否强制刷新,忽略缓存
|
||||||
|
"""
|
||||||
|
# 如果强制刷新,直接调用不带缓存的版本
|
||||||
|
if force:
|
||||||
|
return self._get_plugins_uncached(repo_url, package_version)
|
||||||
|
|
||||||
|
# 正常情况下调用带缓存的版本
|
||||||
|
return self._get_plugins_cached(repo_url, package_version)
|
||||||
|
|
||||||
|
@cached(maxsize=64, ttl=1800)
|
||||||
|
def _get_plugins_cached(self, repo_url: str, package_version: Optional[str] = None) -> Optional[Dict[str, dict]]:
|
||||||
|
"""
|
||||||
|
获取Github所有最新插件列表(使用缓存)
|
||||||
|
:param repo_url: Github仓库地址
|
||||||
|
:param package_version: 首选插件版本 (如 "v2", "v3"),如果不指定则获取 v1 版本
|
||||||
|
"""
|
||||||
|
return self._get_plugins_uncached(repo_url, package_version)
|
||||||
|
|
||||||
|
def _get_plugins_uncached(self, repo_url: str, package_version: Optional[str] = None) -> Optional[Dict[str, dict]]:
|
||||||
|
"""
|
||||||
|
获取Github所有最新插件列表(不使用缓存)
|
||||||
|
:param repo_url: Github仓库地址
|
||||||
|
:param package_version: 首选插件版本 (如 "v2", "v3"),如果不指定则获取 v1 版本
|
||||||
"""
|
"""
|
||||||
if not repo_url:
|
if not repo_url:
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user