This commit is contained in:
Mikan
2026-06-21 02:41:48 +03:00
parent c21a13d2a3
commit bd85e186dc
31 changed files with 1372 additions and 319 deletions

View File

@@ -1,4 +1,4 @@
"""Misc endpoints: health, i18n."""
"""Misc endpoints: health, i18n, public settings."""
from __future__ import annotations
@@ -11,6 +11,7 @@ from app.config import get_settings
from app.core.embeddings import HashEmbedder
from app.core.logging import get_logger
from app.core.qdrant_client import ping_qdrant
from app.core.settings_service import get_all_settings, get_setting
from app.db import get_db
from app.schemas import HealthResponse
@@ -34,12 +35,9 @@ async def health(db: AsyncSession = Depends(get_db)) -> HealthResponse:
except Exception as e: # noqa: BLE001
_logger.warning("health_qdrant_failed", error=str(e))
# LLM health: we treat it as "true" only if api_url is set AND we can avoid a real call.
# For the basic health probe we don't make any LLM calls — return True iff api_url is configured.
cfg = get_settings()
llm_ok = bool(cfg.llm_api_url)
# Embeddings: True if HashEmbedder works (always does) or if openai provider configured
embeddings_ok = True
if cfg.embeddings_provider == "offline_hash":
try:
@@ -59,16 +57,28 @@ async def health(db: AsyncSession = Depends(get_db)) -> HealthResponse:
)
@router.get("/settings/public")
async def public_settings(db: AsyncSession = Depends(get_db)) -> dict:
"""Return UI-relevant settings (no secrets). No auth required.
The frontend uses this on app load to set the page title, favicon,
and logo.
"""
page_title = await get_setting(db, "ui.page_title")
favicon_url = await get_setting(db, "ui.favicon_url")
logo_url = await get_setting(db, "ui.logo_url")
og_image_url = await get_setting(db, "ui.og_image_url")
return {
"page_title": page_title or "AI-RPG",
"favicon_url": favicon_url or "/icon.png",
"logo_url": logo_url or "/icon.png",
"og_image_url": og_image_url or "",
}
@router.get("/i18n/{lang}")
async def i18n(lang: str) -> dict:
"""Return translation JSON for the given language.
Backend only knows the en/ru bundles used by the frontend; we serve them
statically from the frontend's `public/i18n/` folder in production, but
this endpoint is useful for hot-reloading in dev.
"""
"""Return translation JSON for the given language."""
if lang not in ("en", "ru"):
return {"error": "unsupported language"}
# The frontend owns the bundles; this endpoint returns an empty dict
# (the frontend fetches `/i18n/{lang}.json` as a static asset).
return {"language": lang}