diff --git a/plugins/removelink/__init__.py b/plugins/removelink/__init__.py index 1146efd..fcf067e 100644 --- a/plugins/removelink/__init__.py +++ b/plugins/removelink/__init__.py @@ -12,10 +12,12 @@ from app.plugins import _PluginBase from app.schemas import Notification, NotificationType import time + class FileMonitorHandler(FileSystemEventHandler): """ 目录监控处理 """ + def __init__(self, monpath: str, sync: Any, **kwargs): super(FileMonitorHandler, self).__init__(**kwargs) self._watch_path = monpath @@ -29,6 +31,7 @@ class FileMonitorHandler(FileSystemEventHandler): logger.info("监测到删除:%s" % event.src_path) self.sync.event_handler(event=event, event_path=event.src_path) + def updateState(monitor_dirs: List[str]): """ 更新监控目录的文件列表 @@ -48,6 +51,7 @@ def updateState(monitor_dirs: List[str]): return state_set + class RemoveLink(_PluginBase): # 插件名称 plugin_name = "清理硬链接" @@ -72,6 +76,7 @@ class RemoveLink(_PluginBase): _monitor_dirs = "" _exclude_keywords = "" _enabled = False + _notify = False _observer = [] _state_set = set() @@ -254,7 +259,7 @@ class RemoveLink(_PluginBase): if keyword and re.findall(keyword, event_path): logger.info(f"{event_path} 命中过滤关键字 {keyword},不处理") return - + file_path = Path(event_path) current_set = updateState(self._monitor_dirs.split("\n")) deleted_set = self._state_set - current_set @@ -269,12 +274,12 @@ class RemoveLink(_PluginBase): logger.info(f"删除硬链接文件:{path}") except Exception as e: logger.error("目录监控发生错误:%s - %s" % (str(e), traceback.format_exc())) - + if self._notify and (len(deleted_files) != 0): self.chain.post_message(Notification( mtype=NotificationType.SiteMessage, title=f"[删除硬链接]", text=f"根据源文件:{file_path}\n" - f"删除硬链接文件:{[str(x) for x in deleted_files]}", + f"删除硬链接文件:{[str(x) for x in deleted_files]}", )) - self._state_set = updateState(self._monitor_dirs.split("\n")) \ No newline at end of file + self._state_set = updateState(self._monitor_dirs.split("\n"))