Merge pull request #18 from thsrite/main

fix 目录监控插件增加监控文件大小过滤
This commit is contained in:
jxxghp
2023-12-01 10:23:27 +08:00
committed by GitHub
2 changed files with 53 additions and 5 deletions

View File

@@ -42,7 +42,7 @@
"DirMonitor": {
"name": "目录监控",
"description": "监控目录文件发生变化时实时整理到媒体库。",
"version": "1.2",
"version": "1.3",
"icon": "directory.png",
"author": "jxxghp",
"level": 1

View File

@@ -59,7 +59,7 @@ class DirMonitor(_PluginBase):
# 插件图标
plugin_icon = "directory.png"
# 插件版本
plugin_version = "1.2"
plugin_version = "1.3"
# 插件作者
plugin_author = "jxxghp"
# 作者主页
@@ -82,6 +82,7 @@ class DirMonitor(_PluginBase):
_notify = False
_onlyonce = False
_cron = None
_size = 0
# 模式 compatibility/fast
_mode = "fast"
# 转移方式
@@ -117,6 +118,7 @@ class DirMonitor(_PluginBase):
self._exclude_keywords = config.get("exclude_keywords") or ""
self._interval = config.get("interval") or 10
self._cron = config.get("cron")
self._size = config.get("size") or 0
# 停止现有任务
self.stop_service()
@@ -243,7 +245,8 @@ class DirMonitor(_PluginBase):
"monitor_dirs": self._monitor_dirs,
"exclude_keywords": self._exclude_keywords,
"interval": self._interval,
"cron": self._cron
"cron": self._cron,
"size": self._size
})
@eventmanager.register(EventType.PluginAction)
@@ -352,6 +355,11 @@ class DirMonitor(_PluginBase):
logger.error(f"{file_path.name} 无法识别有效信息")
return
# 判断文件大小
if self._size and int(self._size) > 0 and file_path.stat().st_size < int(self._size) * 1024 ** 3:
logger.info(f"{event_path} 文件大小小于监控文件大小,不处理")
return
# 查询转移目的目录
target: Path = self._dirconf.get(mon_path)
# 查询转移方式
@@ -765,7 +773,8 @@ class DirMonitor(_PluginBase):
{
'component': 'VCol',
'props': {
'cols': 12
'cols': 12,
'md': 4
},
'content': [
{
@@ -777,6 +786,23 @@ class DirMonitor(_PluginBase):
}
}
]
},
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VTextField',
'props': {
'model': 'size',
'label': '监控文件大小',
'placeholder': '0'
}
}
]
}
]
},
@@ -848,6 +874,27 @@ class DirMonitor(_PluginBase):
]
}
]
},
{
'component': 'VRow',
'content': [
{
'component': 'VCol',
'props': {
'cols': 12,
},
'content': [
{
'component': 'VAlert',
'props': {
'type': 'info',
'variant': 'tonal',
'text': '监控文件大小默认0单位GB。0为不开启低于监控文件大小的文件不会被监控转移。'
}
}
]
}
]
}
]
}
@@ -860,7 +907,8 @@ class DirMonitor(_PluginBase):
"monitor_dirs": "",
"exclude_keywords": "",
"interval": 10,
"cron": ""
"cron": "",
"size": 0
}
def get_page(self) -> List[dict]: