fix bug
This commit is contained in:
parent
fbe306ba90
commit
cd4229a915
@ -15,25 +15,23 @@ router = APIRouter()
|
||||
@router.get("/", summary="所有插件", response_model=List[schemas.Plugin])
|
||||
def all_plugins(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
查询所有插件清单
|
||||
查询所有插件清单,包括本地插件和在线插件
|
||||
"""
|
||||
# 查询本地插件
|
||||
plugins = []
|
||||
# 本地插件
|
||||
local_plugins = PluginManager().get_local_plugins()
|
||||
# 在线插件
|
||||
online_plugins = PluginManager().get_online_plugins()
|
||||
# 全并去重,在线插件有的以在线插件为准
|
||||
plugins = []
|
||||
if not local_plugins:
|
||||
return online_plugins
|
||||
for plugin in local_plugins:
|
||||
for online_plugin in online_plugins:
|
||||
if plugin["id"] == online_plugin["id"]:
|
||||
plugins.append(online_plugin)
|
||||
break
|
||||
else:
|
||||
plugins.append(plugin)
|
||||
# 已安装插件IDS
|
||||
installed_ids = SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
|
||||
# 已经安装的本地
|
||||
plugins.extend([plugin for plugin in local_plugins if plugin["id"] in installed_ids])
|
||||
# 未安装的线上插件或者有更新的插件
|
||||
for plugin in online_plugins:
|
||||
if plugin not in plugins:
|
||||
if plugin["id"] not in installed_ids:
|
||||
plugins.append(plugin)
|
||||
elif plugin.get("has_update"):
|
||||
plugin["installed"] = False
|
||||
plugins.append(plugin)
|
||||
return plugins
|
||||
|
||||
@ -56,26 +54,19 @@ def install_plugin(plugin_id: str,
|
||||
"""
|
||||
# 已安装插件
|
||||
install_plugins = SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
|
||||
# 重载标志
|
||||
reload_flag = False
|
||||
# 如果是非本地括件,或者强制安装时,则需要下载安装
|
||||
if repo_url and (force or plugin_id not in PluginManager().get_plugin_ids()):
|
||||
# 下载安装
|
||||
state, msg = PluginHelper().install(pid=plugin_id, repo_url=repo_url)
|
||||
if state:
|
||||
# 安装成功
|
||||
reload_flag = True
|
||||
else:
|
||||
if not state:
|
||||
# 安装失败
|
||||
return schemas.Response(success=False, msg=msg)
|
||||
# 安装插件
|
||||
if plugin_id not in install_plugins:
|
||||
reload_flag = True
|
||||
install_plugins.append(plugin_id)
|
||||
# 保存设置
|
||||
SystemConfigOper().set(SystemConfigKey.UserInstalledPlugins, install_plugins)
|
||||
# 重载插件管理器
|
||||
if reload_flag:
|
||||
PluginManager().init_config()
|
||||
return schemas.Response(success=True)
|
||||
|
||||
|
@ -215,24 +215,18 @@ class PluginManager(metaclass=Singleton):
|
||||
conf = {}
|
||||
# ID
|
||||
conf.update({"id": pid})
|
||||
# 安装状态,是否有新版本
|
||||
if plugin_static:
|
||||
# 已安装
|
||||
# 安装状态
|
||||
if pid in installed_apps:
|
||||
conf.update({"installed": True})
|
||||
else:
|
||||
conf.update({"installed": False})
|
||||
# 是否有新版本
|
||||
conf.update({"has_update": False})
|
||||
if plugin_obj:
|
||||
if plugin_static:
|
||||
installed_version = getattr(plugin_static, "plugin_version")
|
||||
if StringUtils.compare_version(installed_version, plugin.get("version")) < 0:
|
||||
# 需要更新
|
||||
conf.update({"installed": False})
|
||||
conf.update({"has_update": True})
|
||||
else:
|
||||
# 未安装
|
||||
conf.update({"installed": False})
|
||||
conf.update({"has_update": False})
|
||||
# 运行状态
|
||||
if plugin_obj and hasattr(plugin_obj, "get_state"):
|
||||
conf.update({"state": plugin_obj.get_state()})
|
||||
|
@ -76,7 +76,7 @@ class PluginHelper(metaclass=Singleton):
|
||||
# 本地存在时先删除
|
||||
plugin_dir = Path(settings.ROOT_PATH) / "app" / "plugins" / pid.lower()
|
||||
if plugin_dir.exists():
|
||||
shutil.rmtree(plugin_dir)
|
||||
shutil.rmtree(plugin_dir, ignore_errors=True)
|
||||
# 下载所有文件
|
||||
for item in ret_json:
|
||||
if item.get("download_url"):
|
||||
|
Loading…
x
Reference in New Issue
Block a user