@@ -39,6 +39,11 @@ async def get_all() -> list[dict[str, Any]]:
3939
4040 return result
4141
42+ @staticmethod
43+ async def has_new () -> str | None :
44+ """是否存在新插件"""
45+ return await redis_client .get (f'{ settings .PLUGIN_REDIS_PREFIX } :new' )
46+
4247 @staticmethod
4348 async def install_zip (* , file : UploadFile ) -> None :
4449 """
@@ -89,6 +94,7 @@ async def install_zip(*, file: UploadFile) -> None:
8994 zf .extractall (os .path .join (PLUGIN_DIR , plugin_name ), members )
9095
9196 await install_requirements_async (plugin_name )
97+ await redis_client .set (f'{ settings .PLUGIN_REDIS_PREFIX } :new' , 'ture' )
9298
9399 @staticmethod
94100 async def install_git (* , repo_url : str ):
@@ -112,6 +118,7 @@ async def install_git(*, repo_url: str):
112118 raise errors .ServerError (msg = '插件安装失败,请稍后重试' ) from e
113119 else :
114120 await install_requirements_async (repo_name )
121+ await redis_client .set (f'{ settings .PLUGIN_REDIS_PREFIX } :new' , 'ture' )
115122
116123 @staticmethod
117124 async def uninstall (* , plugin : str ):
@@ -127,6 +134,7 @@ async def uninstall(*, plugin: str):
127134 await uninstall_requirements_async (plugin )
128135 bacup_dir = os .path .join (PLUGIN_DIR , f'{ plugin } .{ timezone .now ().strftime ("%Y%m%d%H%M%S" )} .backup' )
129136 shutil .move (plugin_dir , bacup_dir )
137+ await redis_client .delete (f'{ settings .PLUGIN_REDIS_PREFIX } :info:{ plugin } ' )
130138
131139 @staticmethod
132140 async def update_status (* , plugin : str ):
@@ -140,12 +148,14 @@ async def update_status(*, plugin: str):
140148 if not plugin_info :
141149 raise errors .ForbiddenError (msg = '插件不存在' )
142150 plugin_info = json .loads (plugin_info )
151+
152+ # 更新持久缓存状态
143153 new_status = (
144154 StatusType .enable .value
145155 if plugin_info .get ('plugin' , {}).get ('enable' ) == StatusType .disable .value
146156 else StatusType .disable .value
147157 )
148- plugin_info ['plugin' ]['enable' ] = new_status
158+ plugin_info ['plugin' ]['enable' ] = str ( new_status )
149159 await redis_client .set (
150160 f'{ settings .PLUGIN_REDIS_PREFIX } :info:{ plugin } ' , json .dumps (plugin_info , ensure_ascii = False )
151161 )
0 commit comments