diff --git a/README.md b/README.md index 22050c3..d704f5a 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ - 清理订阅缓存 1.0 - 添加种子下载 1.0 - 删除站点种子 1.2 -- 插件更新管理 1.6 -- 插件强制重装 1.5 +- 插件更新管理 1.7 +- 插件强制重装 1.7 - 群辉Webhook通知 1.1 - 同步CookieCloud 1.2 - 日程提醒 1.0 diff --git a/package.json b/package.json index f6d6766..33d7026 100644 --- a/package.json +++ b/package.json @@ -90,11 +90,12 @@ "name": "插件更新管理", "description": "监测已安装插件,推送更新提醒,可配置自动更新。", "labels": "自动更新,插件管理", - "version": "1.6", + "version": "1.7", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/pluginupdate.png", "author": "thsrite", "level": 1, "history": { + "v1.7": "插件API立即生效", "v1.6": "插件重载,插件自动更新注册成为服务、命令", "v1.5": "自动更新增加排除列表", "v1.4": "正在运行的插件跳过更新,可选更新插件列表", @@ -108,11 +109,12 @@ "name": "插件强制重装", "description": "卸载当前插件,强制重装。", "labels": "插件管理", - "version": "1.5", + "version": "1.6", "icon": "refresh.png", "author": "thsrite", "level": 1, "history": { + "v1.6": "插件API立即生效", "v1.5": "支持插件热重载", "v1.4": "支持代理地址", "v1.3": "插件重载", diff --git a/plugins/pluginautoupdate/__init__.py b/plugins/pluginautoupdate/__init__.py index 313b63b..01b94d2 100644 --- a/plugins/pluginautoupdate/__init__.py +++ b/plugins/pluginautoupdate/__init__.py @@ -3,6 +3,7 @@ from datetime import datetime, timedelta import pytz from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.triggers.cron import CronTrigger +from fastapi import APIRouter from app.core.config import settings from app.core.plugin import PluginManager @@ -17,6 +18,8 @@ from app.scheduler import Scheduler from app.schemas.types import EventType from app.core.event import eventmanager, Event +router = APIRouter() + class PluginAutoUpdate(_PluginBase): # 插件名称 @@ -26,7 +29,7 @@ class PluginAutoUpdate(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/pluginupdate.png" # 插件版本 - plugin_version = "1.6" + plugin_version = "1.7" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -186,6 +189,8 @@ class PluginAutoUpdate(_PluginBase): PluginManager().reload_plugin(plugin.id) # 注册插件服务 Scheduler().update_plugin_job(plugin.id) + # 注册插件API + self.register_plugin_api(plugin.id) else: title = f"插件 {plugin.plugin_name} 有更新啦" logger.info(f"{title} {version_text}") @@ -256,6 +261,18 @@ class PluginAutoUpdate(_PluginBase): def get_api(self) -> List[Dict[str, Any]]: pass + @staticmethod + def register_plugin_api(plugin_id: str = None): + """ + 注册插件API(先删除后新增) + """ + for api in PluginManager().get_plugin_apis(plugin_id): + for r in router.routes: + if r.path == api.get("path"): + router.routes.remove(r) + break + router.add_api_route(**api) + def get_form(self) -> Tuple[List[dict], Dict[str, Any]]: """ 拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构 diff --git a/plugins/pluginreinstall/__init__.py b/plugins/pluginreinstall/__init__.py index dc29ef3..b0eb99e 100644 --- a/plugins/pluginreinstall/__init__.py +++ b/plugins/pluginreinstall/__init__.py @@ -2,6 +2,8 @@ import re import shutil from pathlib import Path +from fastapi import APIRouter + from app.core.config import settings from app.core.plugin import PluginManager from app.db.systemconfig_oper import SystemConfigOper @@ -15,6 +17,8 @@ from app.utils.string import StringUtils from app.scheduler import Scheduler from app.utils.system import SystemUtils +router = APIRouter() + class PluginReInstall(_PluginBase): # 插件名称 @@ -24,7 +28,7 @@ class PluginReInstall(_PluginBase): # 插件图标 plugin_icon = "refresh.png" # 插件版本 - plugin_version = "1.5" + plugin_version = "1.6" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -102,6 +106,8 @@ class PluginReInstall(_PluginBase): PluginManager().reload_plugin(plugin_id) # 注册插件服务 Scheduler().update_plugin_job(plugin_id) + # 注册插件API + self.register_plugin_api(plugin_id) def __update_conifg(self): self.update_config({ @@ -211,6 +217,18 @@ class PluginReInstall(_PluginBase): return True, "" + @staticmethod + def register_plugin_api(plugin_id: str = None): + """ + 注册插件API(先删除后新增) + """ + for api in PluginManager().get_plugin_apis(plugin_id): + for r in router.routes: + if r.path == api.get("path"): + router.routes.remove(r) + break + router.add_api_route(**api) + def get_state(self) -> bool: return False