Files
MobaXterm-Activator/backend/routes/license_routes.py

37 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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"'}
)