This commit is contained in:
s.mostryukov 2024-10-01 17:38:06 +03:00
parent f85a010efa
commit d1bc1fdf18
9 changed files with 77 additions and 83 deletions

View File

@ -1,10 +0,0 @@
from api.swagger import router as swagger_router
from fastapi import APIRouter
from config import settings
router = APIRouter()
router.include_router(
swagger_router,
prefix=settings.prefix.swagger,
)

View File

@ -5,7 +5,7 @@ import uvicorn
from fastapi import FastAPI
from fastapi.responses import ORJSONResponse
from starlette.staticfiles import StaticFiles
from web.router import router as web_router
from web.routers import router as web_router
input_text = """

View File

@ -1,10 +0,0 @@
from fastapi import APIRouter
from web.router import router as web_router
router = APIRouter()
router.include_router(
web_router,
prefix="",
)

View File

@ -1,61 +0,0 @@
from fastapi import APIRouter, Form
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.templating import Jinja2Templates
from fastapi.openapi.docs import get_swagger_ui_html
from config import settings
from config import TEMPLATES_DIR
from scripts.сheck_available_ports import start_check
router = APIRouter(
tags=["Web"],
)
templates = Jinja2Templates(directory=TEMPLATES_DIR)
@router.get("/web/check_ports", response_class=HTMLResponse)
async def check_ports(request: Request):
return templates.TemplateResponse(
"body-check_ports.html",
{
"request": request,
},
)
@router.get("/web/start_check_ports")
async def start_check_ports(request: Request, inputText: str):
results = start_check(inputText, result_type="test")
return templates.TemplateResponse(
"body-check_ports.html",
{
"request": request,
"results": results,
},
)
@router.get("/docs", include_in_schema=False)
async def custom_swagger_ui_html():
return get_swagger_ui_html(
openapi_url=settings.swagger.openapi_url,
title=settings.swagger.title,
oauth2_redirect_url=settings.swagger.oauth2_redirect_url,
swagger_js_url=settings.swagger.swagger_js_url,
swagger_css_url=settings.swagger.swagger_css_url,
swagger_favicon_url=settings.swagger.swagger_favicon_url,
)
@router.get("/", response_class=HTMLResponse)
async def start_page(request: Request):
return templates.TemplateResponse(
"base.html",
{
"request": request,
},
)

22
web/routers/__init__.py Normal file
View File

@ -0,0 +1,22 @@
from fastapi import APIRouter
from web.routers.swagger import router as swagger_router
from web.routers.check_ports import router as check_ports_router
from web.routers.start_page import router as start_page_router
router = APIRouter(
tags=["Web"],
)
router.include_router(
swagger_router,
prefix="/docs",
)
router.include_router(
check_ports_router,
prefix="/web/check_ports",
)
router.include_router(
start_page_router,
prefix="",
)

View File

@ -0,0 +1,34 @@
from fastapi import APIRouter
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.templating import Jinja2Templates
from config import TEMPLATES_DIR
from scripts.сheck_available_ports import start_check
router = APIRouter()
templates = Jinja2Templates(directory=TEMPLATES_DIR)
@router.get("", response_class=HTMLResponse)
async def check_ports(request: Request):
return templates.TemplateResponse(
"body-check_ports.html",
{
"request": request,
},
)
@router.get("/start")
async def start_check_ports(request: Request, inputText: str):
results = start_check(inputText, result_type="test")
return templates.TemplateResponse(
"body-check_ports.html",
{
"request": request,
"results": results,
},
)

19
web/routers/start_page.py Normal file
View File

@ -0,0 +1,19 @@
from fastapi import APIRouter
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.templating import Jinja2Templates
from config import TEMPLATES_DIR
router = APIRouter()
templates = Jinja2Templates(directory=TEMPLATES_DIR)
@router.get("/", response_class=HTMLResponse)
async def start_page(request: Request):
return templates.TemplateResponse(
"base.html",
{
"request": request,
},
)

View File

@ -4,7 +4,7 @@
<input type="text" id="inputText" name="inputText" placeholder="Введите значение" />
<button hx-get="/web/start_check_ports" hx-include="#inputText" hx-target='#body'>Проверить</button>
<button hx-get="/web/check_ports/start" hx-include="#inputText" hx-target='#body'>Проверить</button>
<div id="result">