Skip to content

Commit

Permalink
feat:支持V2专用插件
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Sep 10, 2024
1 parent d0ac564 commit 8a6ad03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 12 additions & 7 deletions app/core/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,22 +542,23 @@ def get_online_plugins(self) -> List[schemas.Plugin]:
获取所有在线插件信息
"""

def __get_plugin_info(market: str) -> Optional[List[schemas.Plugin]]:
def __get_plugin_info(market: str, version: str = None) -> Optional[List[schemas.Plugin]]:
"""
获取插件信息
"""
online_plugins = self.pluginhelper.get_plugins(market) or {}
online_plugins = self.pluginhelper.get_plugins(repo_url=market, version=version) or {}
if not online_plugins:
logger.warn(f"获取插件库失败:{market}")
return
ret_plugins = []
add_time = len(online_plugins)
for pid, plugin_info in online_plugins.items():
# 版本兼容性控制
if hasattr(settings, 'VERSION_FLAG') \
and not plugin_info.get(settings.VERSION_FLAG):
# 插件当前版本不兼容
continue
if not version:
if hasattr(settings, 'VERSION_FLAG') \
and not plugin_info.get(settings.VERSION_FLAG):
# 插件当前版本不兼容
continue
# 运行状插件
plugin_obj = self._running_plugins.get(pid)
# 非运行态插件
Expand Down Expand Up @@ -644,7 +645,11 @@ def __get_plugin_info(market: str) -> Optional[List[schemas.Plugin]]:
for m in settings.PLUGIN_MARKET.split(","):
if not m:
continue
futures.append(executor.submit(__get_plugin_info, m))
# v1版本插件
futures.append(executor.submit(__get_plugin_info, m, None))
# v2+版本插件
if settings.VERSION_FLAG:
futures.append(executor.submit(__get_plugin_info, m, settings.VERSION_FLAG))
for future in concurrent.futures.as_completed(futures):
plugins = future.result()
if plugins:
Expand Down
6 changes: 4 additions & 2 deletions app/helper/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ def proxies(self):
return None if settings.GITHUB_PROXY else settings.PROXY

@cached(cache=TTLCache(maxsize=1000, ttl=1800))
def get_plugins(self, repo_url: str) -> Dict[str, dict]:
def get_plugins(self, repo_url: str, version: str = None) -> Dict[str, dict]:
"""
获取Github所有最新插件列表
:param repo_url: Github仓库地址
:param version: 版本
"""
if not repo_url:
return {}
user, repo = self.get_repo_info(repo_url)
if not user or not repo:
return {}
raw_url = self._base_url % (user, repo)
package_url = f"{raw_url}package.{version}.json" if version else f"{raw_url}package.json"
res = RequestUtils(proxies=self.proxies,
headers=settings.REPO_GITHUB_HEADERS(repo=f"{user}/{repo}"),
timeout=10).get_res(f"{raw_url}package.json")
timeout=10).get_res(package_url)
if res:
try:
return json.loads(res.text)
Expand Down

0 comments on commit 8a6ad03

Please sign in to comment.