mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-12 22:00:57 +00:00
feat: 插件删除功能
This commit is contained in:
@@ -43,6 +43,21 @@ class PluginsRouterGroup(group.RouterGroup):
|
|||||||
return self.success(data={
|
return self.success(data={
|
||||||
'task_id': wrapper.id
|
'task_id': wrapper.id
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@self.route('/<author>/<plugin_name>', methods=['DELETE'])
|
||||||
|
async def _(author: str, plugin_name: str) -> str:
|
||||||
|
ctx = taskmgr.TaskContext.new()
|
||||||
|
wrapper = self.ap.task_mgr.create_user_task(
|
||||||
|
self.ap.plugin_mgr.uninstall_plugin(plugin_name, task_context=ctx),
|
||||||
|
kind="plugin-operation",
|
||||||
|
name=f'plugin-remove-{plugin_name}',
|
||||||
|
label=f'删除插件 {plugin_name}',
|
||||||
|
context=ctx
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.success(data={
|
||||||
|
'task_id': wrapper.id
|
||||||
|
})
|
||||||
|
|
||||||
@self.route('/reorder', methods=['PUT'])
|
@self.route('/reorder', methods=['PUT'])
|
||||||
async def _() -> str:
|
async def _() -> str:
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class PluginInstaller(metaclass=abc.ABCMeta):
|
|||||||
async def uninstall_plugin(
|
async def uninstall_plugin(
|
||||||
self,
|
self,
|
||||||
plugin_name: str,
|
plugin_name: str,
|
||||||
|
task_context: taskmgr.TaskContext = taskmgr.TaskContext.placeholder(),
|
||||||
):
|
):
|
||||||
"""卸载插件
|
"""卸载插件
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ class GitHubRepoInstaller(installer.PluginInstaller):
|
|||||||
async def uninstall_plugin(
|
async def uninstall_plugin(
|
||||||
self,
|
self,
|
||||||
plugin_name: str,
|
plugin_name: str,
|
||||||
|
task_context: taskmgr.TaskContext = taskmgr.TaskContext.placeholder(),
|
||||||
):
|
):
|
||||||
"""卸载插件
|
"""卸载插件
|
||||||
"""
|
"""
|
||||||
@@ -127,7 +128,9 @@ class GitHubRepoInstaller(installer.PluginInstaller):
|
|||||||
if plugin_container is None:
|
if plugin_container is None:
|
||||||
raise errors.PluginInstallerError('插件不存在或未成功加载')
|
raise errors.PluginInstallerError('插件不存在或未成功加载')
|
||||||
else:
|
else:
|
||||||
shutil.rmtree(plugin_container.pkg_path)
|
task_context.trace("删除插件目录...", "uninstall-plugin")
|
||||||
|
await aioshutil.rmtree(plugin_container.pkg_path)
|
||||||
|
task_context.trace("完成, 重新加载以生效.", "uninstall-plugin")
|
||||||
|
|
||||||
async def update_plugin(
|
async def update_plugin(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -83,10 +83,11 @@ class PluginManager:
|
|||||||
async def uninstall_plugin(
|
async def uninstall_plugin(
|
||||||
self,
|
self,
|
||||||
plugin_name: str,
|
plugin_name: str,
|
||||||
|
task_context: taskmgr.TaskContext = taskmgr.TaskContext.placeholder(),
|
||||||
):
|
):
|
||||||
"""卸载插件
|
"""卸载插件
|
||||||
"""
|
"""
|
||||||
await self.installer.uninstall_plugin(plugin_name)
|
await self.installer.uninstall_plugin(plugin_name, task_context)
|
||||||
|
|
||||||
plugin_container = self.get_plugin_by_name(plugin_name)
|
plugin_container = self.get_plugin_by_name(plugin_name)
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['toggle', 'update', 'uninstall']);
|
const emit = defineEmits(['toggle', 'update', 'remove']);
|
||||||
|
|
||||||
const openGithubSource = () => {
|
const openGithubSource = () => {
|
||||||
window.open(props.plugin.source, '_blank');
|
window.open(props.plugin.source, '_blank');
|
||||||
@@ -73,8 +73,8 @@ const updatePlugin = () => {
|
|||||||
emit('update', props.plugin);
|
emit('update', props.plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uninstallPlugin = () => {
|
const removePlugin = () => {
|
||||||
emit('uninstall', props.plugin);
|
emit('remove', props.plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
@@ -96,7 +96,7 @@ const menuItems = [
|
|||||||
{
|
{
|
||||||
title: '删除',
|
title: '删除',
|
||||||
condition: (plugin) => true,
|
condition: (plugin) => true,
|
||||||
action: uninstallPlugin
|
action: removePlugin
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
</v-card>
|
</v-card>
|
||||||
<div class="plugins-container">
|
<div class="plugins-container">
|
||||||
<PluginCard class="plugin-card" v-for="plugin in plugins" :key="plugin.name" :plugin="plugin"
|
<PluginCard class="plugin-card" v-for="plugin in plugins" :key="plugin.name" :plugin="plugin"
|
||||||
@toggle="togglePlugin" @update="updatePlugin" />
|
@toggle="togglePlugin" @update="updatePlugin" @remove="removePlugin" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -141,6 +141,18 @@ const updatePlugin = (plugin) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const removePlugin = (plugin) => {
|
||||||
|
proxy.$axios.delete(`/plugins/${plugin.author}/${plugin.name}`).then(res => {
|
||||||
|
if (res.data.code != 0) {
|
||||||
|
snackbar.error(res.data.msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
snackbar.success(`已添加删除任务 请到任务列表查看进度`)
|
||||||
|
}).catch(error => {
|
||||||
|
snackbar.error(error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const installPlugin = () => {
|
const installPlugin = () => {
|
||||||
|
|
||||||
if (installDialogSource.value == '' || installDialogSource.value.trim() == '') {
|
if (installDialogSource.value == '' || installDialogSource.value.trim() == '') {
|
||||||
|
|||||||
Reference in New Issue
Block a user