2022-09-09 02:21:52 +00:00
|
|
|
"""
|
|
|
|
Router "misc" provides:
|
|
|
|
|
|
|
|
- getting the project version
|
|
|
|
- getting the device IP
|
|
|
|
"""
|
|
|
|
|
|
|
|
from importlib.metadata import version
|
|
|
|
from logging import getLogger
|
|
|
|
from socket import AF_INET, SOCK_DGRAM, socket
|
|
|
|
|
2022-09-15 22:32:11 +00:00
|
|
|
from fastapi import APIRouter, Depends
|
2022-09-09 02:21:52 +00:00
|
|
|
|
2022-09-17 19:41:41 +00:00
|
|
|
from ...config import Config, LogoUIConfig, ServerUIConfig
|
|
|
|
from ...settings import SETTINGS
|
2022-09-09 02:21:52 +00:00
|
|
|
|
|
|
|
_logger = getLogger(__name__)
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/misc", tags=["misc"])
|
|
|
|
|
|
|
|
|
|
|
|
@router.on_event("startup")
|
|
|
|
async def start_router() -> None:
|
|
|
|
_logger.debug(f"{router.prefix} router starting.")
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/lanip")
|
|
|
|
async def get_ip() -> str:
|
|
|
|
with socket(
|
|
|
|
family=AF_INET,
|
|
|
|
type=SOCK_DGRAM,
|
|
|
|
) as s:
|
|
|
|
s.settimeout(0)
|
|
|
|
try:
|
2022-09-09 02:41:15 +00:00
|
|
|
s.connect((SETTINGS.ping_host, SETTINGS.ping_port))
|
2022-09-09 02:21:52 +00:00
|
|
|
IP = s.getsockname()[0]
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
IP = "127.0.0.1"
|
|
|
|
|
|
|
|
return IP
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/version")
|
|
|
|
async def get_version() -> str:
|
|
|
|
return version("ovdashboard-api")
|
2022-09-15 22:32:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@router.get(
|
|
|
|
"/config/server",
|
|
|
|
response_model=ServerUIConfig,
|
|
|
|
)
|
|
|
|
async def get_server_ui_config(
|
|
|
|
cfg: Config = Depends(Config.get),
|
|
|
|
) -> ServerUIConfig:
|
|
|
|
return cfg.server
|
|
|
|
|
|
|
|
|
|
|
|
@router.get(
|
|
|
|
"/config/logo",
|
|
|
|
response_model=LogoUIConfig,
|
|
|
|
)
|
|
|
|
async def get_logo_ui_config(
|
|
|
|
cfg: Config = Depends(Config.get),
|
|
|
|
) -> LogoUIConfig:
|
|
|
|
return cfg.logo
|