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