Работа с "подделкой" лицензии

This commit is contained in:
2026-03-05 18:46:13 +07:00
parent 92367b9f6e
commit 7f925ef2bd
2 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
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"'
}
)