Skip to content

Commit 9ac18b2

Browse files
committed
Update prompt information
1 parent 54df0f2 commit 9ac18b2

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

backend/app/admin/api/v1/sys/plugin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ async def install_plugin(
4343
file: Annotated[UploadFile | None, File()] = None,
4444
repo_url: Annotated[str | None, Query(description='插件 git 仓库地址')] = None,
4545
) -> ResponseModel:
46-
await plugin_service.install(type=type, file=file, repo_url=repo_url)
46+
plugin_name = await plugin_service.install(type=type, file=file, repo_url=repo_url)
4747
return response_base.success(
48-
res=CustomResponse(code=200, msg='插件安装成功,请根据插件说明(README.md)进行相关配置并重启服务')
48+
res=CustomResponse(
49+
code=200, msg=f'插件 {plugin_name} 安装成功,请根据插件说明(README.md)进行相关配置并重启服务'
50+
)
4951
)
5052

5153

@@ -61,7 +63,7 @@ async def install_plugin(
6163
async def uninstall_plugin(plugin: Annotated[str, Path(description='插件名称')]) -> ResponseModel:
6264
await plugin_service.uninstall(plugin=plugin)
6365
return response_base.success(
64-
res=CustomResponse(code=200, msg='插件卸载成功,请根据插件说明(README.md)移除相关配置并重启服务')
66+
res=CustomResponse(code=200, msg=f'插件 {plugin} 卸载成功,请根据插件说明(README.md)移除相关配置并重启服务')
6567
)
6668

6769

backend/app/admin/service/plugin_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def changed() -> str | None:
4343
return await redis_client.get(f'{settings.PLUGIN_REDIS_PREFIX}:changed')
4444

4545
@staticmethod
46-
async def install(*, type: PluginType, file: UploadFile | None = None, repo_url: str | None = None):
46+
async def install(*, type: PluginType, file: UploadFile | None = None, repo_url: str | None = None) -> str:
4747
"""
4848
安装插件
4949
@@ -55,11 +55,11 @@ async def install(*, type: PluginType, file: UploadFile | None = None, repo_url:
5555
if type == PluginType.zip:
5656
if not file:
5757
raise errors.RequestError(msg='ZIP 压缩包不能为空')
58-
await install_zip_plugin(file)
58+
return await install_zip_plugin(file)
5959
elif type == PluginType.git:
6060
if not repo_url:
6161
raise errors.RequestError(msg='Git 仓库地址不能为空')
62-
await install_git_plugin(repo_url)
62+
return await install_git_plugin(repo_url)
6363

6464
@staticmethod
6565
async def uninstall(*, plugin: str):

backend/cli.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ def run(host: str, port: int, reload: bool, workers: int | None) -> None:
5959
uvicorn.run(app='backend.main:app', host=host, port=port, reload=not reload, workers=workers)
6060

6161

62+
def install_plugin(path: str, repo_url: str) -> None:
63+
if not path and not repo_url:
64+
raise cappa.Exit('path 或 repo_url 必须指定其中一项', code=1)
65+
if path and repo_url:
66+
raise cappa.Exit('path 和 repo_url 不能同时指定', code=1)
67+
68+
plugin_name = None
69+
console.print(Text('开始安装插件...', style='bold cyan'))
70+
71+
try:
72+
if path:
73+
plugin_name = run_await(install_zip_plugin)(file=path)
74+
if repo_url:
75+
plugin_name = run_await(install_git_plugin)(repo_url=repo_url)
76+
except Exception as e:
77+
raise cappa.Exit(e.msg if isinstance(e, BaseExceptionMixin) else str(e), code=1)
78+
79+
console.print(Text(f'插件 {plugin_name} 安装成功', style='bold cyan'))
80+
81+
6282
@cappa.command(help='运行服务')
6383
@dataclass
6484
class Run:
@@ -91,21 +111,17 @@ def __call__(self):
91111
@cappa.command(help='新增插件')
92112
@dataclass
93113
class Add:
94-
path: Annotated[str | None, cappa.Arg(long=True, help='ZIP 插件的本地完整路径')]
95-
repo_url: Annotated[str | None, cappa.Arg(long=True, help='Git 插件的仓库地址')]
114+
path: Annotated[
115+
str | None,
116+
cappa.Arg(long=True, help='ZIP 插件的本地完整路径'),
117+
]
118+
repo_url: Annotated[
119+
str | None,
120+
cappa.Arg(long=True, help='Git 插件的仓库地址'),
121+
]
96122

97123
def __call__(self):
98-
if not self.path and not self.repo_url:
99-
raise cappa.Exit('path 或 repo_url 必须指定其中一项', code=1)
100-
if self.path and self.repo_url:
101-
raise cappa.Exit('path 和 repo_url 不能同时指定', code=1)
102-
try:
103-
if self.path:
104-
run_await(install_zip_plugin)(file=self.path)
105-
if self.repo_url:
106-
run_await(install_git_plugin)(repo_url=self.repo_url)
107-
except Exception as e:
108-
raise cappa.Exit(e.msg if isinstance(e, BaseExceptionMixin) else str(e), code=1)
124+
install_plugin(path=self.path, repo_url=self.repo_url)
109125

110126

111127
@dataclass

backend/utils/file_ops.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async def upload_file(file: UploadFile) -> str:
8181
return filename
8282

8383

84-
async def install_zip_plugin(file: UploadFile | str):
84+
async def install_zip_plugin(file: UploadFile | str) -> str:
8585
"""
8686
安装 ZIP 插件
8787
@@ -135,8 +135,10 @@ async def install_zip_plugin(file: UploadFile | str):
135135
await install_requirements_async(plugin_dir_name)
136136
await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:changed', 'ture')
137137

138+
return plugin_name
138139

139-
async def install_git_plugin(repo_url: str):
140+
141+
async def install_git_plugin(repo_url: str) -> str:
140142
"""
141143
安装 Git 插件
142144
@@ -157,3 +159,5 @@ async def install_git_plugin(repo_url: str):
157159

158160
await install_requirements_async(repo_name)
159161
await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:changed', 'ture')
162+
163+
return repo_name

0 commit comments

Comments
 (0)