Add timestamp to output folder to avoid overwrite conflicts on re-upload

This commit is contained in:
Кирилл Блинов 2026-05-29 12:45:33 +03:00
parent 78e542a246
commit 8bb21d0d7f

View File

@ -87,9 +87,11 @@ async def process_file(file_path: Path, task_id: str):
await _send_progress(task_id, 75, "Генерация документов...", "processing") await _send_progress(task_id, 75, "Генерация документов...", "processing")
# Определяем имена выходных файлов # Определяем имена выходных файлов (уникальная папка с timestamp)
stem = file_path.stem stem = file_path.stem
output_dir = PROCESSED_DIR / stem timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
folder_name = f"{stem}_{timestamp}"
output_dir = PROCESSED_DIR / folder_name
output_dir.mkdir(parents=True, exist_ok=True) output_dir.mkdir(parents=True, exist_ok=True)
# Сохраняем docx и md # Сохраняем docx и md
@ -99,9 +101,8 @@ async def process_file(file_path: Path, task_id: str):
build_document(result["segments"], docx_path, config) build_document(result["segments"], docx_path, config)
build_document(result["segments"], md_path, config) build_document(result["segments"], md_path, config)
# Также сохраняем исходник # Также сохраняем исходник (всегда копируем, так как папка уникальная)
src_copy = output_dir / file_path.name src_copy = output_dir / file_path.name
if not src_copy.exists():
shutil.copy2(str(file_path), str(src_copy)) shutil.copy2(str(file_path), str(src_copy))
result_data = { result_data = {