@@ -39,6 +39,11 @@ async def get_all() -> list[dict[str, Any]]:
39
39
40
40
return result
41
41
42
+ @staticmethod
43
+ async def has_new () -> str | None :
44
+ """是否存在新插件"""
45
+ return await redis_client .get (f'{ settings .PLUGIN_REDIS_PREFIX } :new' )
46
+
42
47
@staticmethod
43
48
async def install_zip (* , file : UploadFile ) -> None :
44
49
"""
@@ -89,6 +94,7 @@ async def install_zip(*, file: UploadFile) -> None:
89
94
zf .extractall (os .path .join (PLUGIN_DIR , plugin_name ), members )
90
95
91
96
await install_requirements_async (plugin_name )
97
+ await redis_client .set (f'{ settings .PLUGIN_REDIS_PREFIX } :new' , 'ture' )
92
98
93
99
@staticmethod
94
100
async def install_git (* , repo_url : str ):
@@ -112,6 +118,7 @@ async def install_git(*, repo_url: str):
112
118
raise errors .ServerError (msg = '插件安装失败,请稍后重试' ) from e
113
119
else :
114
120
await install_requirements_async (repo_name )
121
+ await redis_client .set (f'{ settings .PLUGIN_REDIS_PREFIX } :new' , 'ture' )
115
122
116
123
@staticmethod
117
124
async def uninstall (* , plugin : str ):
@@ -127,6 +134,7 @@ async def uninstall(*, plugin: str):
127
134
await uninstall_requirements_async (plugin )
128
135
bacup_dir = os .path .join (PLUGIN_DIR , f'{ plugin } .{ timezone .now ().strftime ("%Y%m%d%H%M%S" )} .backup' )
129
136
shutil .move (plugin_dir , bacup_dir )
137
+ await redis_client .delete (f'{ settings .PLUGIN_REDIS_PREFIX } :info:{ plugin } ' )
130
138
131
139
@staticmethod
132
140
async def update_status (* , plugin : str ):
@@ -140,12 +148,14 @@ async def update_status(*, plugin: str):
140
148
if not plugin_info :
141
149
raise errors .ForbiddenError (msg = '插件不存在' )
142
150
plugin_info = json .loads (plugin_info )
151
+
152
+ # 更新持久缓存状态
143
153
new_status = (
144
154
StatusType .enable .value
145
155
if plugin_info .get ('plugin' , {}).get ('enable' ) == StatusType .disable .value
146
156
else StatusType .disable .value
147
157
)
148
- plugin_info ['plugin' ]['enable' ] = new_status
158
+ plugin_info ['plugin' ]['enable' ] = str ( new_status )
149
159
await redis_client .set (
150
160
f'{ settings .PLUGIN_REDIS_PREFIX } :info:{ plugin } ' , json .dumps (plugin_info , ensure_ascii = False )
151
161
)
0 commit comments