Simplify architecture: remove overengineering, flatten structure

- Remove dead code: cache.py, context_managers.py, decorators.py, flask-limiter
- Replace AudioSource ABC + FakeFile (5 classes) with 4 plain functions
- Replace TempFileManager class with create_temp_file/cleanup_temp_files functions
- Simplify RequestLogger from 233 to 65 lines, remove file reading side-effect
- Convert HistoryLogger and AudioUtils classes to module-level functions
- Remove unused speed_up_audio and audio_speed_factor config
- Flatten single-file directories: shared/, api/, storage/, validation/, async_tasks/, logging/
- Merge logging config + request_logger into single infrastructure/log.py
- Fix request_logging config key (was request_logger)
- Trim CLAUDE.md to high-level only

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serge Zaigraeff
2026-03-22 05:28:34 +03:00
co-authored by Claude Opus 4.6
parent 38785398b3
commit 2e2bad8255
30 changed files with 556 additions and 1407 deletions
+46
View File
@@ -0,0 +1,46 @@
"""
Утилиты для управления временными файлами.
"""
import os
import uuid
import tempfile
import logging
logger = logging.getLogger('app.file_manager')
def create_temp_file(suffix: str = ".wav") -> str:
"""
Создаёт временный файл с уникальным именем.
Args:
suffix: Расширение временного файла.
Returns:
Путь к временному файлу.
"""
temp_dir = tempfile.mkdtemp()
temp_path = os.path.join(temp_dir, f"{uuid.uuid4()}{suffix}")
logger.debug(f"Создан временный файл: {temp_path}")
return temp_path
def cleanup_temp_files(file_paths: list) -> None:
"""
Удаляет временные файлы и их директории.
Args:
file_paths: Список путей к файлам для удаления.
"""
for path in file_paths:
try:
if os.path.exists(path):
os.remove(path)
logger.debug(f"Удалён временный файл: {path}")
temp_dir = os.path.dirname(path)
if os.path.exists(temp_dir) and not os.listdir(temp_dir):
os.rmdir(temp_dir)
except Exception as e:
logger.warning(f"Не удалось очистить временный файл {path}: {e}")