Генератор файла лицензии
This commit is contained in:
36
backend/routes/license_routes.py
Normal file
36
backend/routes/license_routes.py
Normal file
@@ -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"'}
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user