Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions alist-sync-web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
11 changes: 11 additions & 0 deletions alist_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ <h1>Alist-Sync 配置中心</h1>
<input type="radio" name="syncDelAction_1" value="delete" title="删除目标目录多余项" lay-group="syncDelAction_1">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label" title="同步时强制覆盖,不判断文件大小和修改时间!谨慎选择!">强制覆盖</label>
<div class="layui-input-block">
<input type="checkbox" name="forceOverwrite[]" title="同步强制覆盖文件">
</div>
</div>
<!-- 同步模式选择 -->
<div class="layui-form-item">
<label class="layui-form-label">同步模式</label>
Expand Down Expand Up @@ -1194,7 +1200,9 @@ <h1>Alist-Sync 配置中心</h1>
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') {
Expand Down Expand Up @@ -1504,6 +1512,9 @@ <h1>Alist-Sync 配置中心</h1>
$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));
}
Expand Down