Files
whisper-api-server/app/infrastructure/storage.py
T
Serge ZaigraeffandClaude Sonnet 4.6 ca2e41e0f5 Refactor logging, clean dead code, fix temp files and async tasks
- Replace f-string logging with % formatting throughout
- Fix create_temp_file: use mkstemp() instead of mkdtemp() (no leaked dirs)
- Add cleanup background thread and copy.deepcopy to AsyncTaskManager
- Fix transcribe_audio_async signature to accept transcription_service + params
- Use resample_poly instead of scipy_resample for better audio quality
- Remove unused validate_file/BinaryIO methods from FileValidator
- Add requests to requirements.txt
- Add error handling for pip install in server.sh
- Add __all__ and module docstrings to __init__.py files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 00:43:53 +03:00

42 lines
1.2 KiB
Python

"""
Утилиты для управления временными файлами.
"""
import os
import tempfile
import logging
logger = logging.getLogger('app.file_manager')
def create_temp_file(suffix: str = ".wav") -> str:
"""
Создаёт временный файл с уникальным именем.
Args:
suffix: Расширение временного файла.
Returns:
Путь к временному файлу.
"""
fd, temp_path = tempfile.mkstemp(suffix=suffix)
os.close(fd)
logger.debug("Создан временный файл: %s", 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("Удалён временный файл: %s", path)
except Exception as e:
logger.warning("Не удалось очистить временный файл %s: %s", path, e)