From cbecb0b6f9938795fe15a8489876ca102b77dce1 Mon Sep 17 00:00:00 2001 From: thsrite Date: Tue, 25 Jun 2024 14:20:29 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E4=BA=91=E7=9B=98=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=88=A0=E9=99=A4v1.1=20=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E6=8C=89=E9=92=AE=EF=BC=88=E4=B8=8D=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=96=87=E4=BB=B6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- package.json | 1 + plugins/cloudsyncdel/__init__.py | 38 ++++++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4416ea2..a0f1a8b 100644 --- a/README.md +++ b/README.md @@ -45,4 +45,4 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ - 云盘助手(docs%2FCloudAssistant.md) v1.9 - CloudDrive2助手 v1.2 - 软连接重定向 v1.0 -- 云盘同步删除 v1.0 \ No newline at end of file +- 云盘同步删除 v1.1 \ No newline at end of file diff --git a/package.json b/package.json index 91590f8..6249ff5 100644 --- a/package.json +++ b/package.json @@ -573,6 +573,7 @@ "author": "thsrite", "level": 2, "history": { + "v1.1": "增加测试模式按钮(不删除文件)", "v1.0": "媒体库删除软连接文件后,同步删除云盘文件" } } diff --git a/plugins/cloudsyncdel/__init__.py b/plugins/cloudsyncdel/__init__.py index 2c8d648..0068fe5 100644 --- a/plugins/cloudsyncdel/__init__.py +++ b/plugins/cloudsyncdel/__init__.py @@ -1,4 +1,3 @@ -import os import shutil import time from pathlib import Path @@ -11,7 +10,6 @@ from app.plugins import _PluginBase from typing import Any, List, Dict, Tuple from app.schemas.types import EventType, MediaImageType, NotificationType, MediaType -from app.utils.system import SystemUtils class CloudSyncDel(_PluginBase): @@ -22,7 +20,7 @@ class CloudSyncDel(_PluginBase): # 插件图标 plugin_icon = "clouddisk.png" # 插件版本 - plugin_version = "1.0" + plugin_version = "1.1" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -40,6 +38,7 @@ class CloudSyncDel(_PluginBase): _paths = {} _cloud_paths = {} _notify = False + _test = False _del_history = False _video_formats = ('.mp4', '.avi', '.rmvb', '.wmv', '.mov', '.mkv', '.flv', '.ts', '.webm', '.iso', '.mpg') @@ -48,6 +47,7 @@ class CloudSyncDel(_PluginBase): if config: self._enabled = config.get("enabled") self._notify = config.get("notify") + self._test = config.get("test") or True self._del_history = config.get("del_history") if config.get("path"): for path in str(config.get("path")).split("\n"): @@ -109,14 +109,16 @@ class CloudSyncDel(_PluginBase): logger.info(f"开始筛选 {cloud_file_path.parent} 下同名文件 {pattern}") files = cloud_file_path.parent.glob(f"{pattern}.*") for file in files: - Path(file).unlink() + if not self._test: + Path(file).unlink() logger.info(f"云盘文件 {file} 已删除") cloud_file_flag = True else: # 删除云盘文件 cloud_path = self.__get_path(self._cloud_paths, str(media_path)) if Path(cloud_path).exists(): - shutil.rmtree(cloud_path) + if not self._test: + shutil.rmtree(cloud_path) logger.warn(f"云盘目录 {cloud_path} 已删除") cloud_file_flag = True @@ -252,7 +254,7 @@ class CloudSyncDel(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 4 + 'md': 3 }, 'content': [ { @@ -268,7 +270,7 @@ class CloudSyncDel(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 4 + 'md': 3 }, 'content': [ { @@ -284,14 +286,31 @@ class CloudSyncDel(_PluginBase): 'component': 'VCol', 'props': { 'cols': 12, - 'md': 4 + 'md': 3 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'test', + 'label': '测试模式', + 'placeholder': '测试模式下不会真正删除文件,仅仅模拟删除操作' + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 3 }, 'content': [ { 'component': 'VSwitch', 'props': { 'model': 'del_history', - 'label': '删除历史', + 'label': '清空历史', } } ] @@ -372,6 +391,7 @@ class CloudSyncDel(_PluginBase): "enabled": False, "path": "", "notify": False, + "test": True, "del_history": False }