diff --git a/app/plugins/__init__.py b/app/plugins/__init__.py index 392ca73e..0457f468 100644 --- a/app/plugins/__init__.py +++ b/app/plugins/__init__.py @@ -4,13 +4,12 @@ from typing import Any, List, Dict, Tuple from app.chain import ChainBase from app.core.config import settings -from app.core.event import EventManager, eventmanager, Event +from app.core.event import EventManager from app.db.models import Base from app.db.plugindata_oper import PluginDataOper from app.db.systemconfig_oper import SystemConfigOper from app.helper.message import MessageHelper from app.schemas import Notification, NotificationType, MessageChannel -from app.schemas.types import EventType class PluginChian(ChainBase): @@ -182,17 +181,4 @@ class _PluginBase(metaclass=ABCMeta): self.chain.post_message(Notification( channel=channel, mtype=mtype, title=title, text=text, image=image, link=link, userid=userid - )) - - @eventmanager.register(EventType.PluginReload) - def reload(self, event: Event): - """ - 重新加载插件 - """ - plugin_id = event.event_data.get("plugin_id") - if not plugin_id: - return - conf = self.get_config(plugin_id) - if not conf: - return - self.init_plugin(conf) + )) \ No newline at end of file diff --git a/app/plugins/customhosts/__init__.py b/app/plugins/customhosts/__init__.py index c5c44421..4a69b6d0 100644 --- a/app/plugins/customhosts/__init__.py +++ b/app/plugins/customhosts/__init__.py @@ -1,8 +1,11 @@ from typing import List, Tuple, Dict, Any from python_hosts import Hosts, HostsEntry + +from app.core.event import eventmanager from app.log import logger from app.plugins import _PluginBase +from app.schemas.types import EventType from app.utils.ip import IpUtils from app.utils.system import SystemUtils @@ -221,3 +224,15 @@ class CustomHosts(_PluginBase): 退出插件 """ pass + + @eventmanager.register(EventType.PluginReload) + def reload(self, event): + """ + 响应插件重载事件 + """ + plugin_id = event.event_data.get("plugin_id") + if not plugin_id: + return + if plugin_id != self.__class__.__name__: + return + return self.init_plugin(self.get_config()) diff --git a/app/plugins/mediasyncdel/__init__.py b/app/plugins/mediasyncdel/__init__.py index 56b43c6f..77e56ec2 100644 --- a/app/plugins/mediasyncdel/__init__.py +++ b/app/plugins/mediasyncdel/__init__.py @@ -492,7 +492,7 @@ class MediaSyncDel(_PluginBase): try: # 判断种子是否被删除完 self.handle_torrent(history_id=transferhis.id, - src=history.src, + src=transferhis.src, torrent_hash=history.download_hash) except Exception as e: logger.error("删除种子失败,尝试删除源文件:%s" % str(e)) @@ -640,7 +640,7 @@ class MediaSyncDel(_PluginBase): try: # 判断种子是否被删除完 self.handle_torrent(history_id=transferhis.id, - src=history.src, + src=transferhis.src, torrent_hash=history.download_hash) except Exception as e: logger.error("删除种子失败,尝试删除源文件:%s" % str(e))