Skip to content

Commit d1c2443

Browse files
authored
🐛 修复webui下载分支 (#2099)
1 parent 5e30694 commit d1c2443

File tree

6 files changed

+51
-34
lines changed

6 files changed

+51
-34
lines changed

zhenxun/builtin_plugins/admin/plugin_switch/__init__.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async def _(
120120
):
121121
if not all.result and not plugin_name.available:
122122
await MessageUtils.build_message("请输入功能/被动名称").finish(reply_to=True)
123-
name = plugin_name.result
123+
name = plugin_name.result.strip()
124124
if session.group:
125125
group_id = session.group.id
126126
"""修改当前群组的数据"""
@@ -234,7 +234,7 @@ async def _(
234234
):
235235
if not all.result and not plugin_name.available:
236236
await MessageUtils.build_message("请输入功能/被动名称").finish(reply_to=True)
237-
name = plugin_name.result
237+
name = plugin_name.result.strip()
238238
if session.group:
239239
group_id = session.group.id
240240
"""修改当前群组的数据"""
@@ -321,13 +321,29 @@ async def _(
321321
session=session,
322322
)
323323
else:
324+
parsed_block_type = (
325+
block_type.result.lower()
326+
if block_type.available and block_type.result
327+
else ""
328+
)
329+
# 兼容中文快捷命令:`关闭功能名 p/g/a`
330+
if not parsed_block_type and " " in name:
331+
split_name = name.rsplit(maxsplit=1)
332+
if len(split_name) == 2 and split_name[1].lower() in {
333+
"a",
334+
"all",
335+
"g",
336+
"group",
337+
"p",
338+
"private",
339+
}:
340+
name = split_name[0].strip()
341+
parsed_block_type = split_name[1].lower()
324342
_type = BlockType.ALL
325-
if block_type.result in ["p", "private"]:
326-
if block_type.available:
327-
_type = BlockType.PRIVATE
328-
elif block_type.result in ["g", "group"]:
329-
if block_type.available:
330-
_type = BlockType.GROUP
343+
if parsed_block_type in {"p", "private"}:
344+
_type = BlockType.PRIVATE
345+
elif parsed_block_type in {"g", "group"}:
346+
_type = BlockType.GROUP
331347
result = await PluginManager.superuser_block(name, _type, group_id)
332348
logger.info(
333349
f"超级用户关闭功能 {name}, 禁用类型: {_type}",

zhenxun/builtin_plugins/admin/plugin_switch/_data_source.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ async def build_task(group_id: str | None) -> BuildImage:
142142

143143

144144
class PluginManager:
145+
@staticmethod
146+
async def _get_plugin_by_name_or_module(plugin_name: str) -> PluginInfo | None:
147+
plugin_name = plugin_name.strip()
148+
if not plugin_name:
149+
return None
150+
if plugin_name.isdigit():
151+
return await PluginInfo.get_or_none(id=int(plugin_name))
152+
plugin = await PluginInfo.get_or_none(
153+
name=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
154+
)
155+
if plugin:
156+
return plugin
157+
return await PluginInfo.get_or_none(
158+
module=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
159+
)
160+
145161
@classmethod
146162
async def set_default_status(cls, plugin_name: str, status: bool) -> str:
147163
"""设置插件进群默认状态
@@ -153,12 +169,7 @@ async def set_default_status(cls, plugin_name: str, status: bool) -> str:
153169
返回:
154170
str: 返回信息
155171
"""
156-
if plugin_name.isdigit():
157-
plugin = await PluginInfo.get_or_none(id=int(plugin_name))
158-
else:
159-
plugin = await PluginInfo.get_or_none(
160-
name=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
161-
)
172+
plugin = await cls._get_plugin_by_name_or_module(plugin_name)
162173
if plugin:
163174
plugin.default_status = status
164175
await plugin.save(update_fields=["default_status"])
@@ -478,12 +489,7 @@ async def _change_group_plugin(
478489
str: 返回信息
479490
"""
480491

481-
if plugin_name.isdigit():
482-
plugin = await PluginInfo.get_or_none(id=int(plugin_name))
483-
else:
484-
plugin = await PluginInfo.get_or_none(
485-
name=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
486-
)
492+
plugin = await cls._get_plugin_by_name_or_module(plugin_name)
487493
if plugin:
488494
status_str = "开启" if status else "关闭"
489495
if status:
@@ -535,12 +541,7 @@ async def superuser_block(
535541
返回:
536542
str: 返回信息
537543
"""
538-
if plugin_name.isdigit():
539-
plugin = await PluginInfo.get_or_none(id=int(plugin_name))
540-
else:
541-
plugin = await PluginInfo.get_or_none(
542-
name=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
543-
)
544+
plugin = await cls._get_plugin_by_name_or_module(plugin_name)
544545
if plugin:
545546
if group_id:
546547
if not await GroupConsole.is_superuser_block_plugin(
@@ -576,12 +577,7 @@ async def superuser_unblock(
576577
返回:
577578
str: 返回信息
578579
"""
579-
if plugin_name.isdigit():
580-
plugin = await PluginInfo.get_or_none(id=int(plugin_name))
581-
else:
582-
plugin = await PluginInfo.get_or_none(
583-
name=plugin_name, load_status=True, plugin_type__not=PluginType.PARENT
584-
)
580+
plugin = await cls._get_plugin_by_name_or_module(plugin_name)
585581
if plugin:
586582
if group_id:
587583
if await GroupConsole.is_superuser_block_plugin(

zhenxun/builtin_plugins/auto_update/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async def _(
112112
try:
113113
result += await UpdateManager.update_webui(
114114
source_str, # type: ignore
115-
"test",
115+
"dist",
116116
True,
117117
)
118118
except Exception as e:

zhenxun/builtin_plugins/plugin_store/data_source.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ async def install_plugin_with_repo(
272272
repo_type = RepoType.ALIYUN
273273
elif source == "git":
274274
repo_type = RepoType.GITHUB
275+
else:
276+
if plugin_info.ali_url:
277+
repo_type = RepoType.ALIYUN
275278
module_path = plugin_info.module_path
276279
is_dir = plugin_info.is_dir
277280
github_url = plugin_info.github_url

zhenxun/builtin_plugins/plugin_store/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class StorePluginInfo(BaseModel):
5757
"""是否为文件夹插件"""
5858
github_url: str | None = None
5959
"""github链接"""
60+
ali_url: str | None = None
61+
"""ali链接"""
6062

6163
@property
6264
def plugin_type_name(self):

zhenxun/builtin_plugins/web_ui/public/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def favicon():
2121
async def init_public(app: FastAPI):
2222
try:
2323
if not ZhenxunRepoManager.check_webui_exists():
24-
await ZhenxunRepoManager.webui_update(branch="test")
24+
await ZhenxunRepoManager.webui_update(branch="dist")
2525
folders = [
2626
x.name for x in ZhenxunRepoManager.config.WEBUI_PATH.iterdir() if x.is_dir()
2727
]

0 commit comments

Comments
 (0)