@@ -53,15 +53,21 @@ async def install_zip(*, file: UploadFile) -> None:
53
53
raise errors .ForbiddenError (msg = '插件压缩包格式非法' )
54
54
with zipfile .ZipFile (file_bytes ) as zf :
55
55
# 校验压缩包
56
- plugin_dir_in_zip = file .filename [:- 4 ]
57
- members_in_plugin_dir = [name for name in zf .namelist () if name .startswith (plugin_dir_in_zip )]
56
+ plugin_dir = file .filename [:- 4 ]
57
+ members_in_plugin_dir = [name for name in zf .namelist () if name .startswith (plugin_dir )]
58
58
if not members_in_plugin_dir :
59
59
raise errors .ForbiddenError (msg = '插件压缩包内容非法' )
60
- plugin_name = members_in_plugin_dir [1 ].replace (plugin_dir_in_zip , '' ).replace ('/' , '' )
60
+ plugin_name = (
61
+ members_in_plugin_dir [0 ]
62
+ .replace ('/' , '' )
63
+ .replace ('-master' , '' )
64
+ .replace ('-main' , '' )
65
+ .replace ('-dev' , '' )
66
+ )
61
67
if (
62
68
len (members_in_plugin_dir ) <= 3
63
- or f'{ plugin_dir_in_zip } /plugin.toml' not in members_in_plugin_dir
64
- or f'{ plugin_dir_in_zip } /README.md' not in members_in_plugin_dir
69
+ or f'{ plugin_dir } /plugin.toml' not in members_in_plugin_dir
70
+ or f'{ plugin_dir } /README.md' not in members_in_plugin_dir
65
71
):
66
72
raise errors .ForbiddenError (msg = '插件压缩包内缺少必要文件' )
67
73
@@ -75,12 +81,12 @@ async def install_zip(*, file: UploadFile) -> None:
75
81
# 解压(安装)
76
82
members = []
77
83
for member in zf .infolist ():
78
- if member .filename .startswith (plugin_dir_in_zip ):
79
- new_filename = member .filename .replace (plugin_dir_in_zip , '' )
84
+ if member .filename .startswith (plugin_dir ):
85
+ new_filename = member .filename .replace (plugin_dir , '' )
80
86
if new_filename :
81
87
member .filename = new_filename
82
88
members .append (member )
83
- zf .extractall (PLUGIN_DIR , members )
89
+ zf .extractall (os . path . join ( PLUGIN_DIR , plugin_name ) , members )
84
90
85
91
await install_requirements_async (plugin_name )
86
92
0 commit comments