mirror of
https://github.com/thsrite/MoviePilot-Plugins.git
synced 2026-03-27 10:05:57 +00:00
feat 插件彻底卸载插件
This commit is contained in:
@@ -31,4 +31,5 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/
|
||||
- 订阅下载统计 1.5
|
||||
- [自定义命令 1.5](docs%2FCustomCommand.md)
|
||||
- docker自定义任务 1.2
|
||||
- 插件彻底卸载 1.0
|
||||
|
||||
|
||||
BIN
icons/uninstall.png
Normal file
BIN
icons/uninstall.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.6 KiB |
11
package.json
11
package.json
@@ -290,5 +290,16 @@
|
||||
"v1.1": "修复多个任务立即运行一次",
|
||||
"v1.0": "init"
|
||||
}
|
||||
},
|
||||
"PluginUnInstall": {
|
||||
"name": "插件彻底卸载",
|
||||
"description": "删除数据库中已安装插件记录、清理插件文件。",
|
||||
"version": "1.0",
|
||||
"icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/uninstall.png",
|
||||
"author": "thsrite",
|
||||
"level": 1,
|
||||
"history": {
|
||||
"v1.0": "init"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
181
plugins/pluginuninstall/__init__.py
Normal file
181
plugins/pluginuninstall/__init__.py
Normal file
@@ -0,0 +1,181 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from app.core.config import settings
|
||||
from app.db.systemconfig_oper import SystemConfigOper
|
||||
from app.helper.plugin import PluginHelper
|
||||
from app.plugins import _PluginBase
|
||||
from typing import Any, List, Dict, Tuple
|
||||
from app.log import logger
|
||||
from app.schemas.types import SystemConfigKey
|
||||
from app.utils.string import StringUtils
|
||||
|
||||
|
||||
class PluginUnInstall(_PluginBase):
|
||||
# 插件名称
|
||||
plugin_name = "插件彻底卸载"
|
||||
# 插件描述
|
||||
plugin_desc = "删除数据库中已安装插件记录、清理插件文件。"
|
||||
# 插件图标
|
||||
plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/uninstall.png"
|
||||
# 插件版本
|
||||
plugin_version = "1.0"
|
||||
# 插件作者
|
||||
plugin_author = "thsrite"
|
||||
# 作者主页
|
||||
author_url = "https://github.com/thsrite"
|
||||
# 插件配置项ID前缀
|
||||
plugin_config_prefix = "pluginuninstall_"
|
||||
# 加载顺序
|
||||
plugin_order = 98
|
||||
# 可使用的用户级别
|
||||
auth_level = 1
|
||||
|
||||
# 私有属性
|
||||
_plugin_ids = []
|
||||
|
||||
def init_plugin(self, config: dict = None):
|
||||
if config:
|
||||
self._plugin_ids = config.get("plugin_ids") or []
|
||||
if not self._plugin_ids:
|
||||
return
|
||||
|
||||
# 已安装插件
|
||||
install_plugins = SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
|
||||
|
||||
new_install_plugins = []
|
||||
for install_plugin in install_plugins:
|
||||
if install_plugin in self._plugin_ids:
|
||||
# 删除插件文件
|
||||
plugin_dir = Path(settings.ROOT_PATH) / "app" / "plugins" / install_plugin.lower()
|
||||
if plugin_dir.exists():
|
||||
shutil.rmtree(plugin_dir, ignore_errors=True)
|
||||
logger.info(f"插件 {install_plugin} 已卸载")
|
||||
else:
|
||||
new_install_plugins.append(install_plugin)
|
||||
|
||||
# 保存已安装插件
|
||||
SystemConfigOper().set(SystemConfigKey.UserInstalledPlugins, new_install_plugins)
|
||||
|
||||
def get_state(self) -> bool:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def get_command() -> List[Dict[str, Any]]:
|
||||
pass
|
||||
|
||||
def get_api(self) -> List[Dict[str, Any]]:
|
||||
pass
|
||||
|
||||
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
|
||||
"""
|
||||
拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构
|
||||
"""
|
||||
# 已安装插件
|
||||
local_plugins = self.get_local_plugins()
|
||||
# 编历 local_plugins,生成插件类型选项
|
||||
pluginOptions = []
|
||||
|
||||
for plugin_id in list(local_plugins.keys()):
|
||||
local_plugin = local_plugins.get(plugin_id)
|
||||
pluginOptions.append({
|
||||
"title": f"{local_plugin.get('plugin_name')} v{local_plugin.get('plugin_version')}",
|
||||
"value": local_plugin.get("id")
|
||||
})
|
||||
return [
|
||||
{
|
||||
'component': 'VForm',
|
||||
'content': [
|
||||
{
|
||||
'component': 'VRow',
|
||||
'content': [
|
||||
{
|
||||
'component': 'VCol',
|
||||
'props': {
|
||||
'cols': 12,
|
||||
'md': 4
|
||||
},
|
||||
'content': [
|
||||
{
|
||||
'component': 'VSelect',
|
||||
'props': {
|
||||
'multiple': True,
|
||||
'chips': True,
|
||||
'model': 'plugin_ids',
|
||||
'label': '重装插件',
|
||||
'items': pluginOptions
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
'component': 'VRow',
|
||||
'content': [
|
||||
{
|
||||
'component': 'VCol',
|
||||
'props': {
|
||||
'cols': 12,
|
||||
},
|
||||
'content': [
|
||||
{
|
||||
'component': 'VAlert',
|
||||
'props': {
|
||||
'type': 'info',
|
||||
'variant': 'tonal',
|
||||
'text': '删除数据库中已安装插件记录、清理插件文件。'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
], {
|
||||
"plugin_ids": []
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def get_local_plugins():
|
||||
"""
|
||||
获取本地插件
|
||||
"""
|
||||
# 已安装插件
|
||||
install_plugins = SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
|
||||
|
||||
local_plugins = {}
|
||||
# 线上插件列表
|
||||
markets = settings.PLUGIN_MARKET.split(",")
|
||||
for market in markets:
|
||||
online_plugins = PluginHelper().get_plugins(market) or {}
|
||||
for pid, plugin in online_plugins.items():
|
||||
if pid in install_plugins:
|
||||
local_plugin = local_plugins.get(pid)
|
||||
if local_plugin:
|
||||
if StringUtils.compare_version(local_plugin.get("plugin_version"), plugin.get("version")) < 0:
|
||||
local_plugins[pid] = {
|
||||
"id": pid,
|
||||
"plugin_name": plugin.get("name"),
|
||||
"repo_url": market,
|
||||
"plugin_version": plugin.get("version")
|
||||
}
|
||||
else:
|
||||
local_plugins[pid] = {
|
||||
"id": pid,
|
||||
"plugin_name": plugin.get("name"),
|
||||
"repo_url": market,
|
||||
"plugin_version": plugin.get("version")
|
||||
}
|
||||
|
||||
return local_plugins
|
||||
|
||||
def get_page(self) -> List[dict]:
|
||||
pass
|
||||
|
||||
def stop_service(self):
|
||||
"""
|
||||
退出插件
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user