added api
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.api.routes import character, chat, fitness, health, memory, pomodoro, projects, webhooks
|
||||
from app.api.routes import character, chat, fitness, health, homelab, media, memory, pomodoro, projects, webhooks
|
||||
|
||||
api_router = APIRouter(prefix="/api/v1")
|
||||
api_router.include_router(health.router, tags=["health"])
|
||||
api_router.include_router(homelab.router, tags=["homelab"])
|
||||
api_router.include_router(chat.router, prefix="/chat", tags=["chat"])
|
||||
api_router.include_router(pomodoro.router, prefix="/pomodoro", tags=["pomodoro"])
|
||||
api_router.include_router(character.router, tags=["character"])
|
||||
@@ -11,3 +12,4 @@ api_router.include_router(projects.router, tags=["projects"])
|
||||
api_router.include_router(memory.router, tags=["memory"])
|
||||
api_router.include_router(fitness.router, tags=["fitness"])
|
||||
api_router.include_router(webhooks.router, tags=["webhooks"])
|
||||
api_router.include_router(media.router, tags=["media"])
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import httpx
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.config import get_settings
|
||||
from app.homelab.comfyui import _use_anima
|
||||
|
||||
router = APIRouter(prefix="/homelab", tags=["homelab"])
|
||||
|
||||
|
||||
def _probe(url: str, *, timeout: float = 10.0) -> dict:
|
||||
try:
|
||||
with httpx.Client(timeout=timeout) as client:
|
||||
response = client.get(url)
|
||||
body = response.text[:500]
|
||||
return {
|
||||
"ok": response.status_code < 400,
|
||||
"status_code": response.status_code,
|
||||
"preview": body,
|
||||
}
|
||||
except Exception as exc:
|
||||
return {"ok": False, "error": str(exc)}
|
||||
|
||||
|
||||
@router.get("/status")
|
||||
def homelab_status() -> dict:
|
||||
settings = get_settings()
|
||||
comfy_backend = "anima" if _use_anima(settings) else "checkpoint"
|
||||
return {
|
||||
"openmeteo": _probe(f"{settings.openmeteo_base_url.rstrip('/')}/v1/forecast?latitude=0&longitude=0¤t=temperature_2m"),
|
||||
"comfyui": _probe(f"{settings.comfyui_base_url.rstrip('/')}/system_stats"),
|
||||
"netdata": _probe(f"{settings.netdata_base_url.rstrip('/')}/api/v1/info"),
|
||||
"config": {
|
||||
"openmeteo_base_url": settings.openmeteo_base_url,
|
||||
"comfyui_base_url": settings.comfyui_base_url,
|
||||
"comfyui_backend": comfy_backend,
|
||||
"comfyui_unet": settings.comfyui_unet,
|
||||
"netdata_base_url": settings.netdata_base_url,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
from app.config import get_settings
|
||||
|
||||
router = APIRouter(prefix="/media", tags=["media"])
|
||||
|
||||
|
||||
@router.get("/generated/{filename}")
|
||||
def get_generated_image(filename: str) -> FileResponse:
|
||||
if ".." in filename or "/" in filename or "\\" in filename:
|
||||
raise HTTPException(status_code=400, detail="Invalid filename")
|
||||
|
||||
settings = get_settings()
|
||||
path = Path(settings.generated_media_dir) / filename
|
||||
if not path.is_file():
|
||||
raise HTTPException(status_code=404, detail="File not found")
|
||||
|
||||
return FileResponse(path, media_type="image/png")
|
||||
Reference in New Issue
Block a user