From 79e302a9d550555a5a0f78a7009bbcdc40a9c41b Mon Sep 17 00:00:00 2001 From: MXG <18631674759@163.com> Date: Mon, 30 Jun 2025 17:11:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BC=BA=E5=88=B6=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alist-sync-web.py | 3 +++ alist_sync.py | 11 +++++++++++ templates/index.html | 13 ++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/alist-sync-web.py b/alist-sync-web.py index 3396bf1..7304b5d 100644 --- a/alist-sync-web.py +++ b/alist-sync-web.py @@ -504,6 +504,9 @@ def _execute_single_task(self, task: Dict): if task.get('regexPatterns'): os.environ['REGEX_PATTERNS'] = task.get('regexPatterns') + # 添加强制覆盖环境变量 + os.environ['FORCE_OVERWRITE'] = str(task.get('forceOverwrite')) + if task['syncMode'] == 'data': self._handle_data_sync(task) elif task['syncMode'] == 'file': diff --git a/alist_sync.py b/alist_sync.py index 1407bee..7d97803 100644 --- a/alist_sync.py +++ b/alist_sync.py @@ -497,6 +497,17 @@ def _copy_item_with_check(self, src_dir: str, dst_dir: str, item: Dict) -> bool: logger.info(f"复制文件: {item_name}") return self._copy_item(src_dir, dst_dir, item_name) else: + # 设置了强制覆盖后执行覆盖操作 + force_overwrite = os.environ.get("FORCE_OVERWRITE", "false").lower() == "true" + if force_overwrite: + logger.info(f"强制覆盖文件: {item_name}") + # 删除旧文件 + if not self._directory_operation("remove", dir=dst_dir, names=[item_name]): + logger.error(f"删除目标文件失败: {dst_path}") + return False + # 复制新文件 + return self._copy_item(src_dir, dst_dir, item_name) + # 获取源文件和目标文件信息 src_size = item.get("size") dst_info = self.get_file_info(dst_path) diff --git a/templates/index.html b/templates/index.html index 5c3e3a5..8a43bb4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -333,6 +333,12 @@

Alist-Sync 配置中心

+
+ +
+ +
+
@@ -1194,7 +1200,9 @@

Alist-Sync 配置中心

syncDelAction: $task.find(`input[name="syncDelAction_${taskId}"]:checked`).val(), syncMode: syncMode, excludeDirs: $task.find('input[name="excludeDirs[]"]').val(), - cron: $task.find('input[name="cron[]"]').val() + cron: $task.find('input[name="cron[]"]').val(), + // 收集强制覆盖状态 + forceOverwrite: $task.find(`input[name="forceOverwrite[]"]`).is(':checked') }; if(syncMode === 'data') { @@ -1504,6 +1512,9 @@

Alist-Sync 配置中心

$task.find('input[name="regexPatterns[]"]').val(task.regexPatterns); } + // 回显强制覆盖状态 + $task.find(`input[name="forceOverwrite[]"]`).prop('checked', task.forceOverwrite); + // 等待一小段时间确保DOM更新完成 await new Promise(resolve => setTimeout(resolve, 50)); }