diff --git a/backend/routes/license_routes.py b/backend/routes/license_routes.py index 9bbcc11..f48e20c 100644 --- a/backend/routes/license_routes.py +++ b/backend/routes/license_routes.py @@ -5,6 +5,7 @@ from ..services.license_service import generate_license_file router: APIRouter = APIRouter() + @router.post("/generate", response_class=FileResponse) async def generate_license( background_tasks: BackgroundTasks, @@ -25,12 +26,19 @@ async def generate_license( # Создаём временный файл на сервере filepath, temp_dir = generate_license_file(name, version) except Exception as e: - raise HTTPException(status_code=500, detail=f"Ошибка генерации лицензии: {e}") + raise HTTPException( + status_code=500, + detail=f"Ошибка генерации лицензии: {e}" + ) + # Удаляем директорию (и файл внутри) после отправки пользователю background_tasks.add_task(temp_dir.cleanup) + # Отправляем с фиксированным именем Custom.mxtpro return FileResponse( filepath, media_type="application/octet-stream", - headers={"Content-Disposition": 'attachment; filename="Custom.mxtpro"'} + headers={ + "Content-Disposition": 'attachment; filename="Custom.mxtpro"' + } )