feat: 添加后端部署和API基本检索的Docker Compose配置
- 引入新的`docker-compose.yml`文件,便于后端和MQTT代理(EMQX)的部署。 - 更新多个组件中的API基本检索,使用函数进行动态解析。 - 加强了多个组件中API调用的错误处理和日志记录。 - 优化了AI聊天面板离线场景的回退响应。 - 更新DataScreen和MediaScreen组件中的数据显示和统计,以反映准确的指标。 - 重构MQTT连接逻辑,以支持动态凭证和客户端ID。
This commit is contained in:
@@ -85,6 +85,17 @@ class ChatBody(BaseModel):
|
||||
|
||||
# ==================== 认证 / 设置 ====================
|
||||
|
||||
@router.get("/api/health")
|
||||
async def health():
|
||||
"""健康检查(Docker healthcheck / 运维探活)"""
|
||||
return {
|
||||
"ok": True,
|
||||
"service": "dpm-backend",
|
||||
"mqtt": hub.connected if getattr(hub, "connected", None) is not None else False,
|
||||
"ts": __import__("time").time(),
|
||||
}
|
||||
|
||||
|
||||
@router.post("/api/login")
|
||||
async def login(request: Request):
|
||||
form = await request.form()
|
||||
@@ -98,6 +109,28 @@ async def get_settings():
|
||||
return {k: s[k] for k in ("volume", "play_mode", "image_duration", "fullscreen", "autostart")}
|
||||
|
||||
|
||||
@router.get("/api/config")
|
||||
async def runtime_config():
|
||||
"""运行配置(供前端启动引导覆盖):MQTT 地址/账号、API 基址
|
||||
—— 打包部署时展播端从后端拉取,避免构建期写死的局域网 IP 失效
|
||||
"""
|
||||
ws = settings.MQTT_WS_URL
|
||||
# 从 ws://host:port/mqtt 中提取 broker 主机
|
||||
host = "127.0.0.1"
|
||||
try:
|
||||
host = ws.split("://", 1)[1].split(":", 1)[0]
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
return {
|
||||
"ok": True,
|
||||
"mqtt_url": ws,
|
||||
"mqtt_username": settings.MQTT_USERNAME or "",
|
||||
"mqtt_password": settings.MQTT_PASSWORD or "",
|
||||
"api_base": f"http://{host}:{settings.PORT}",
|
||||
"broker_host": host,
|
||||
}
|
||||
|
||||
|
||||
@router.post("/api/settings")
|
||||
async def update_settings(body: SettingsBody):
|
||||
storage.update_settings(**body.model_dump(exclude_none=True))
|
||||
|
||||
Reference in New Issue
Block a user