@@ -55,24 +55,24 @@ async def install_zip(*, file: UploadFile) -> None:
5555 contents = await file .read ()
5656 file_bytes = io .BytesIO (contents )
5757 if not zipfile .is_zipfile (file_bytes ):
58- raise errors .ForbiddenError (msg = '插件压缩包格式非法' )
58+ raise errors .RequestError (msg = '插件压缩包格式非法' )
5959 with zipfile .ZipFile (file_bytes ) as zf :
6060 # 校验压缩包
6161 plugin_namelist = zf .namelist ()
6262 plugin_name = plugin_namelist [0 ].split ('/' )[0 ]
6363 if not plugin_namelist or plugin_name not in file .filename :
64- raise errors .ForbiddenError (msg = '插件压缩包内容非法' )
64+ raise errors .RequestError (msg = '插件压缩包内容非法' )
6565 if (
6666 len (plugin_namelist ) <= 3
6767 or f'{ plugin_name } /plugin.toml' not in plugin_namelist
6868 or f'{ plugin_name } /README.md' not in plugin_namelist
6969 ):
70- raise errors .ForbiddenError (msg = '插件压缩包内缺少必要文件' )
70+ raise errors .RequestError (msg = '插件压缩包内缺少必要文件' )
7171
7272 # 插件是否可安装
7373 full_plugin_path = os .path .join (PLUGIN_DIR , plugin_name )
7474 if os .path .exists (full_plugin_path ):
75- raise errors .ForbiddenError (msg = '此插件已安装' )
75+ raise errors .ConflictError (msg = '此插件已安装' )
7676 else :
7777 os .makedirs (full_plugin_path , exist_ok = True )
7878
@@ -99,11 +99,11 @@ async def install_git(*, repo_url: str):
9999 """
100100 match = is_git_url (repo_url )
101101 if not match :
102- raise errors .ForbiddenError (msg = 'Git 仓库地址格式非法' )
102+ raise errors .RequestError (msg = 'Git 仓库地址格式非法' )
103103 repo_name = match .group ('repo' )
104104 plugins = await redis_client .lrange (settings .PLUGIN_REDIS_PREFIX , 0 , - 1 )
105105 if repo_name in plugins :
106- raise errors .ForbiddenError (msg = f'{ repo_name } 插件已安装' )
106+ raise errors .ConflictError (msg = f'{ repo_name } 插件已安装' )
107107 try :
108108 porcelain .clone (repo_url , os .path .join (PLUGIN_DIR , repo_name ), checkout = True )
109109 except Exception as e :
@@ -124,11 +124,11 @@ async def install(self, *, type: PluginType, file: UploadFile | None = None, rep
124124 """
125125 if type == PluginType .zip :
126126 if not file :
127- raise errors .ForbiddenError (msg = 'ZIP 压缩包不能为空' )
127+ raise errors .RequestError (msg = 'ZIP 压缩包不能为空' )
128128 await self .install_zip (file = file )
129129 elif type == PluginType .git :
130130 if not repo_url :
131- raise errors .ForbiddenError (msg = 'Git 仓库地址不能为空' )
131+ raise errors .RequestError (msg = 'Git 仓库地址不能为空' )
132132 await self .install_git (repo_url = repo_url )
133133
134134 @staticmethod
@@ -141,7 +141,7 @@ async def uninstall(*, plugin: str):
141141 """
142142 plugin_dir = os .path .join (PLUGIN_DIR , plugin )
143143 if not os .path .exists (plugin_dir ):
144- raise errors .ForbiddenError (msg = '插件不存在' )
144+ raise errors .NotFoundError (msg = '插件不存在' )
145145 await uninstall_requirements_async (plugin )
146146 bacup_dir = os .path .join (PLUGIN_DIR , f'{ plugin } .{ timezone .now ().strftime ("%Y%m%d%H%M%S" )} .backup' )
147147 shutil .move (plugin_dir , bacup_dir )
@@ -159,7 +159,7 @@ async def update_status(*, plugin: str):
159159 """
160160 plugin_info = await redis_client .get (f'{ settings .PLUGIN_REDIS_PREFIX } :info:{ plugin } ' )
161161 if not plugin_info :
162- raise errors .ForbiddenError (msg = '插件不存在' )
162+ raise errors .NotFoundError (msg = '插件不存在' )
163163 plugin_info = json .loads (plugin_info )
164164
165165 # 更新持久缓存状态
@@ -184,7 +184,7 @@ async def build(*, plugin: str) -> io.BytesIO:
184184 """
185185 plugin_dir = os .path .join (PLUGIN_DIR , plugin )
186186 if not os .path .exists (plugin_dir ):
187- raise errors .ForbiddenError (msg = '插件不存在' )
187+ raise errors .NotFoundError (msg = '插件不存在' )
188188
189189 bio = io .BytesIO ()
190190 with zipfile .ZipFile (bio , 'w' ) as zf :
0 commit comments