🐛 修复webui下载分支 (#2099)

This commit is contained in:
HibiKier
2026-02-09 15:56:44 +08:00
committed by GitHub
parent 5e30694663
commit d1c24436ce
6 changed files with 51 additions and 34 deletions
@@ -120,7 +120,7 @@ async def _(
): ):
if not all.result and not plugin_name.available: if not all.result and not plugin_name.available:
await MessageUtils.build_message("请输入功能/被动名称").finish(reply_to=True) await MessageUtils.build_message("请输入功能/被动名称").finish(reply_to=True)
name = plugin_name.result name = plugin_name.result.strip()
if session.group: if session.group:
group_id = session.group.id group_id = session.group.id
"""修改当前群组的数据""" """修改当前群组的数据"""
@@ -234,7 +234,7 @@ async def _(
): ):
if not all.result and not plugin_name.available: if not all.result and not plugin_name.available:
await MessageUtils.build_message("请输入功能/被动名称").finish(reply_to=True) await MessageUtils.build_message("请输入功能/被动名称").finish(reply_to=True)
name = plugin_name.result name = plugin_name.result.strip()
if session.group: if session.group:
group_id = session.group.id group_id = session.group.id
"""修改当前群组的数据""" """修改当前群组的数据"""
@@ -321,13 +321,29 @@ async def _(
session=session, session=session,
) )
else: else:
parsed_block_type = (
block_type.result.lower()
if block_type.available and block_type.result
else ""
)
# 兼容中文快捷命令:`关闭功能名 p/g/a`
if not parsed_block_type and " " in name:
split_name = name.rsplit(maxsplit=1)
if len(split_name) == 2 and split_name[1].lower() in {
"a",
"all",
"g",
"group",
"p",
"private",
}:
name = split_name[0].strip()
parsed_block_type = split_name[1].lower()
_type = BlockType.ALL _type = BlockType.ALL
if block_type.result in ["p", "private"]: if parsed_block_type in {"p", "private"}:
if block_type.available: _type = BlockType.PRIVATE
_type = BlockType.PRIVATE elif parsed_block_type in {"g", "group"}:
elif block_type.result in ["g", "group"]: _type = BlockType.GROUP
if block_type.available:
_type = BlockType.GROUP
result = await PluginManager.superuser_block(name, _type, group_id) result = await PluginManager.superuser_block(name, _type, group_id)
logger.info( logger.info(
f"超级用户关闭功能 {name}, 禁用类型: {_type}", f"超级用户关闭功能 {name}, 禁用类型: {_type}",
@@ -142,6 +142,22 @@ async def build_task(group_id: str | None) -> BuildImage:
class PluginManager: class PluginManager:
@staticmethod
async def _get_plugin_by_name_or_module(plugin_name: str) -> PluginInfo | None:
plugin_name = plugin_name.strip()
if not plugin_name:
return None
if plugin_name.isdigit():
return await PluginInfo.get_or_none(id=int(plugin_name))
plugin = await PluginInfo.get_or_none(
name=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
)
if plugin:
return plugin
return await PluginInfo.get_or_none(
module=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
)
@classmethod @classmethod
async def set_default_status(cls, plugin_name: str, status: bool) -> str: async def set_default_status(cls, plugin_name: str, status: bool) -> str:
"""设置插件进群默认状态 """设置插件进群默认状态
@@ -153,12 +169,7 @@ class PluginManager:
返回: 返回:
str: 返回信息 str: 返回信息
""" """
if plugin_name.isdigit(): plugin = await cls._get_plugin_by_name_or_module(plugin_name)
plugin = await PluginInfo.get_or_none(id=int(plugin_name))
else:
plugin = await PluginInfo.get_or_none(
name=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
)
if plugin: if plugin:
plugin.default_status = status plugin.default_status = status
await plugin.save(update_fields=["default_status"]) await plugin.save(update_fields=["default_status"])
@@ -478,12 +489,7 @@ class PluginManager:
str: 返回信息 str: 返回信息
""" """
if plugin_name.isdigit(): plugin = await cls._get_plugin_by_name_or_module(plugin_name)
plugin = await PluginInfo.get_or_none(id=int(plugin_name))
else:
plugin = await PluginInfo.get_or_none(
name=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
)
if plugin: if plugin:
status_str = "开启" if status else "关闭" status_str = "开启" if status else "关闭"
if status: if status:
@@ -535,12 +541,7 @@ class PluginManager:
返回: 返回:
str: 返回信息 str: 返回信息
""" """
if plugin_name.isdigit(): plugin = await cls._get_plugin_by_name_or_module(plugin_name)
plugin = await PluginInfo.get_or_none(id=int(plugin_name))
else:
plugin = await PluginInfo.get_or_none(
name=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
)
if plugin: if plugin:
if group_id: if group_id:
if not await GroupConsole.is_superuser_block_plugin( if not await GroupConsole.is_superuser_block_plugin(
@@ -576,12 +577,7 @@ class PluginManager:
返回: 返回:
str: 返回信息 str: 返回信息
""" """
if plugin_name.isdigit(): plugin = await cls._get_plugin_by_name_or_module(plugin_name)
plugin = await PluginInfo.get_or_none(id=int(plugin_name))
else:
plugin = await PluginInfo.get_or_none(
name=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
)
if plugin: if plugin:
if group_id: if group_id:
if await GroupConsole.is_superuser_block_plugin( if await GroupConsole.is_superuser_block_plugin(
@@ -112,7 +112,7 @@ async def _(
try: try:
result += await UpdateManager.update_webui( result += await UpdateManager.update_webui(
source_str, # type: ignore source_str, # type: ignore
"test", "dist",
True, True,
) )
except Exception as e: except Exception as e:
@@ -272,6 +272,9 @@ class StoreManager:
repo_type = RepoType.ALIYUN repo_type = RepoType.ALIYUN
elif source == "git": elif source == "git":
repo_type = RepoType.GITHUB repo_type = RepoType.GITHUB
else:
if plugin_info.ali_url:
repo_type = RepoType.ALIYUN
module_path = plugin_info.module_path module_path = plugin_info.module_path
is_dir = plugin_info.is_dir is_dir = plugin_info.is_dir
github_url = plugin_info.github_url github_url = plugin_info.github_url
@@ -57,6 +57,8 @@ class StorePluginInfo(BaseModel):
"""是否为文件夹插件""" """是否为文件夹插件"""
github_url: str | None = None github_url: str | None = None
"""github链接""" """github链接"""
ali_url: str | None = None
"""ali链接"""
@property @property
def plugin_type_name(self): def plugin_type_name(self):
@@ -21,7 +21,7 @@ async def favicon():
async def init_public(app: FastAPI): async def init_public(app: FastAPI):
try: try:
if not ZhenxunRepoManager.check_webui_exists(): if not ZhenxunRepoManager.check_webui_exists():
await ZhenxunRepoManager.webui_update(branch="test") await ZhenxunRepoManager.webui_update(branch="dist")
folders = [ folders = [
x.name for x in ZhenxunRepoManager.config.WEBUI_PATH.iterdir() if x.is_dir() x.name for x in ZhenxunRepoManager.config.WEBUI_PATH.iterdir() if x.is_dir()
] ]