Улучшение генератора
This commit is contained in:
@@ -5,6 +5,7 @@ from ..services.license_service import generate_license_file
|
|||||||
|
|
||||||
router: APIRouter = APIRouter()
|
router: APIRouter = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.post("/generate", response_class=FileResponse)
|
@router.post("/generate", response_class=FileResponse)
|
||||||
async def generate_license(
|
async def generate_license(
|
||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
@@ -25,12 +26,19 @@ async def generate_license(
|
|||||||
# Создаём временный файл на сервере
|
# Создаём временный файл на сервере
|
||||||
filepath, temp_dir = generate_license_file(name, version)
|
filepath, temp_dir = generate_license_file(name, version)
|
||||||
except Exception as e:
|
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)
|
background_tasks.add_task(temp_dir.cleanup)
|
||||||
|
|
||||||
# Отправляем с фиксированным именем Custom.mxtpro
|
# Отправляем с фиксированным именем Custom.mxtpro
|
||||||
return FileResponse(
|
return FileResponse(
|
||||||
filepath,
|
filepath,
|
||||||
media_type="application/octet-stream",
|
media_type="application/octet-stream",
|
||||||
headers={"Content-Disposition": 'attachment; filename="Custom.mxtpro"'}
|
headers={
|
||||||
|
"Content-Disposition": 'attachment; filename="Custom.mxtpro"'
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user