From c7256c1a54235ea07cf998445b8752699e63bd16 Mon Sep 17 00:00:00 2001 From: Whyverum Date: Mon, 1 Dec 2025 18:16:47 +0700 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=D0=BD=D0=B7=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/routes/license_routes.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 backend/routes/license_routes.py diff --git a/backend/routes/license_routes.py b/backend/routes/license_routes.py new file mode 100644 index 0000000..9bbcc11 --- /dev/null +++ b/backend/routes/license_routes.py @@ -0,0 +1,36 @@ +from typing import Any +from fastapi import APIRouter, Form, HTTPException, BackgroundTasks +from fastapi.responses import FileResponse +from ..services.license_service import generate_license_file + +router: APIRouter = APIRouter() + +@router.post("/generate", response_class=FileResponse) +async def generate_license( + background_tasks: BackgroundTasks, + name: str = Form(...), + version: str = Form(...) +) -> Any: + """ + Генерация лицензии Custom.mxtpro. + Параметры: + - name: str - имя пользователя + - version: str - версия формата X.Y + Возвращает: + - FileResponse: сгенерированный ZIP файл с именем Custom.mxtpro + """ + if not name.strip() or not version.strip(): + raise HTTPException(status_code=400, detail="NAME и VERSION обязательны.") + try: + # Создаём временный файл на сервере + filepath, temp_dir = generate_license_file(name, version) + except Exception as 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"'} + )