mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
✨ 修复插件商店数据源逻辑,优化插件获取流程
This commit is contained in:
parent
6e58818e8b
commit
6bf4714c7f
@ -60,7 +60,6 @@ class StoreManager:
|
|||||||
返回:
|
返回:
|
||||||
list[StorePluginInfo]: 插件列表数据
|
list[StorePluginInfo]: 插件列表数据
|
||||||
"""
|
"""
|
||||||
return []
|
|
||||||
repo_info = GithubUtils.parse_github_url(DEFAULT_GITHUB_URL)
|
repo_info = GithubUtils.parse_github_url(DEFAULT_GITHUB_URL)
|
||||||
if await repo_info.update_repo_commit():
|
if await repo_info.update_repo_commit():
|
||||||
logger.info(f"获取最新提交: {repo_info.branch}", LOG_COMMAND)
|
logger.info(f"获取最新提交: {repo_info.branch}", LOG_COMMAND)
|
||||||
@ -69,6 +68,7 @@ class StoreManager:
|
|||||||
default_github_url = await repo_info.get_raw_download_urls("plugins.json")
|
default_github_url = await repo_info.get_raw_download_urls("plugins.json")
|
||||||
response = await AsyncHttpx.get(default_github_url, check_status_code=200)
|
response = await AsyncHttpx.get(default_github_url, check_status_code=200)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
|
logger.info("获取github插件列表成功", LOG_COMMAND)
|
||||||
return [StorePluginInfo(**detail) for detail in json.loads(response.text)]
|
return [StorePluginInfo(**detail) for detail in json.loads(response.text)]
|
||||||
else:
|
else:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@ -86,6 +86,7 @@ class StoreManager:
|
|||||||
url = f"{GITEE_RAW_URL}/plugins.json"
|
url = f"{GITEE_RAW_URL}/plugins.json"
|
||||||
response = await AsyncHttpx.get(url, check_status_code=200)
|
response = await AsyncHttpx.get(url, check_status_code=200)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
|
logger.info("获取gitee插件列表成功", LOG_COMMAND)
|
||||||
return [StorePluginInfo(**detail) for detail in json.loads(response.text)]
|
return [StorePluginInfo(**detail) for detail in json.loads(response.text)]
|
||||||
else:
|
else:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@ -124,8 +125,7 @@ class StoreManager:
|
|||||||
list[StorePluginInfo]: 插件信息数据
|
list[StorePluginInfo]: 插件信息数据
|
||||||
"""
|
"""
|
||||||
plugins = await cls.get_github_plugins() or await cls.get_gitee_plugins()
|
plugins = await cls.get_github_plugins() or await cls.get_gitee_plugins()
|
||||||
# extra_plugins = await cls.get_extra_plugins()
|
extra_plugins = await cls.get_extra_plugins()
|
||||||
extra_plugins = []
|
|
||||||
return [*plugins, *extra_plugins]
|
return [*plugins, *extra_plugins]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -232,13 +232,12 @@ class StoreManager:
|
|||||||
logger.info(f"正在安装插件 {plugin_key}...", LOG_COMMAND)
|
logger.info(f"正在安装插件 {plugin_key}...", LOG_COMMAND)
|
||||||
download_type = "GITHUB"
|
download_type = "GITHUB"
|
||||||
try:
|
try:
|
||||||
# await cls.install_plugin_with_repo(
|
await cls.install_plugin_with_repo(
|
||||||
# plugin_info.github_url,
|
plugin_info.github_url,
|
||||||
# plugin_info.module_path,
|
plugin_info.module_path,
|
||||||
# plugin_info.is_dir,
|
plugin_info.is_dir,
|
||||||
# is_external,
|
is_external,
|
||||||
# )
|
)
|
||||||
pass
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
download_type = "GITEE"
|
download_type = "GITEE"
|
||||||
logger.error(f"GITHUB 插件 {plugin_key} 更新失败", LOG_COMMAND, e=e)
|
logger.error(f"GITHUB 插件 {plugin_key} 更新失败", LOG_COMMAND, e=e)
|
||||||
|
|||||||
@ -22,9 +22,9 @@ router = APIRouter(prefix="/store")
|
|||||||
async def _() -> Result[dict]:
|
async def _() -> Result[dict]:
|
||||||
try:
|
try:
|
||||||
require("plugin_store")
|
require("plugin_store")
|
||||||
from zhenxun.builtin_plugins.plugin_store import ShopManage
|
from zhenxun.builtin_plugins.plugin_store import StoreManager
|
||||||
|
|
||||||
data = await ShopManage.get_data()
|
data = await StoreManager.get_data()
|
||||||
plugin_list = [
|
plugin_list = [
|
||||||
{**data[name].to_dict(), "name": name, "id": idx}
|
{**data[name].to_dict(), "name": name, "id": idx}
|
||||||
for idx, name in enumerate(data)
|
for idx, name in enumerate(data)
|
||||||
@ -48,9 +48,9 @@ async def _() -> Result[dict]:
|
|||||||
async def _(param: PluginIr) -> Result:
|
async def _(param: PluginIr) -> Result:
|
||||||
try:
|
try:
|
||||||
require("plugin_store")
|
require("plugin_store")
|
||||||
from zhenxun.builtin_plugins.plugin_store import ShopManage
|
from zhenxun.builtin_plugins.plugin_store import StoreManager
|
||||||
|
|
||||||
result = await ShopManage.add_plugin(param.id) # type: ignore
|
result = await StoreManager.add_plugin(param.id) # type: ignore
|
||||||
return Result.ok(info=result)
|
return Result.ok(info=result)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Result.fail(f"安装插件失败: {type(e)}: {e}")
|
return Result.fail(f"安装插件失败: {type(e)}: {e}")
|
||||||
@ -66,9 +66,9 @@ async def _(param: PluginIr) -> Result:
|
|||||||
async def _(param: PluginIr) -> Result:
|
async def _(param: PluginIr) -> Result:
|
||||||
try:
|
try:
|
||||||
require("plugin_store")
|
require("plugin_store")
|
||||||
from zhenxun.builtin_plugins.plugin_store import ShopManage
|
from zhenxun.builtin_plugins.plugin_store import StoreManager
|
||||||
|
|
||||||
result = await ShopManage.update_plugin(param.id) # type: ignore
|
result = await StoreManager.update_plugin(param.id) # type: ignore
|
||||||
return Result.ok(info=result)
|
return Result.ok(info=result)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Result.fail(f"更新插件失败: {type(e)}: {e}")
|
return Result.fail(f"更新插件失败: {type(e)}: {e}")
|
||||||
@ -84,9 +84,9 @@ async def _(param: PluginIr) -> Result:
|
|||||||
async def _(param: PluginIr) -> Result:
|
async def _(param: PluginIr) -> Result:
|
||||||
try:
|
try:
|
||||||
require("plugin_store")
|
require("plugin_store")
|
||||||
from zhenxun.builtin_plugins.plugin_store import ShopManage
|
from zhenxun.builtin_plugins.plugin_store import StoreManager
|
||||||
|
|
||||||
result = await ShopManage.remove_plugin(param.id) # type: ignore
|
result = await StoreManager.remove_plugin(param.id) # type: ignore
|
||||||
return Result.ok(info=result)
|
return Result.ok(info=result)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Result.fail(f"移除插件失败: {type(e)}: {e}")
|
return Result.fail(f"移除插件失败: {type(e)}: {e}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user