更新 GitHub Actions 工作流,统一使用 ubuntu-24.04 作为运行环境;新增发布 WebUI 产物的工作流
This commit is contained in:
@@ -215,6 +215,12 @@ class ConfigManager:
|
||||
def register_reload_callback(self, callback: Callable[[], object]) -> None:
|
||||
self._reload_callbacks.append(callback)
|
||||
|
||||
def unregister_reload_callback(self, callback: Callable[[], object]) -> None:
|
||||
try:
|
||||
self._reload_callbacks.remove(callback)
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
async def reload_config(self) -> bool:
|
||||
async with self._reload_lock:
|
||||
try:
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"""FastAPI 应用工厂 - 创建和配置 WebUI 应用实例"""
|
||||
|
||||
import mimetypes
|
||||
from importlib import import_module
|
||||
from pathlib import Path
|
||||
import mimetypes
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse
|
||||
@@ -113,12 +114,15 @@ def _setup_static_files(app: FastAPI):
|
||||
mimetypes.add_type("text/css", ".css")
|
||||
mimetypes.add_type("application/json", ".json")
|
||||
|
||||
base_dir = Path(__file__).parent.parent.parent
|
||||
static_path = base_dir / "webui" / "dist"
|
||||
static_path = _resolve_static_path()
|
||||
if static_path is None:
|
||||
logger.warning("❌ WebUI 静态文件目录不存在")
|
||||
logger.warning("💡 请先构建前端: cd dashboard && npm run build")
|
||||
return
|
||||
|
||||
if not static_path.exists():
|
||||
logger.warning(f"❌ WebUI 静态文件目录不存在: {static_path}")
|
||||
logger.warning("💡 请先构建前端: cd webui && npm run build")
|
||||
logger.warning("💡 请先构建前端: cd dashboard && npm run build")
|
||||
return
|
||||
|
||||
if not (static_path / "index.html").exists():
|
||||
@@ -148,6 +152,24 @@ def _setup_static_files(app: FastAPI):
|
||||
logger.info(f"✅ WebUI 静态文件服务已配置: {static_path}")
|
||||
|
||||
|
||||
def _resolve_static_path() -> Path | None:
|
||||
try:
|
||||
module = import_module("maibot_dashboard")
|
||||
get_dist_path = getattr(module, "get_dist_path", None)
|
||||
if callable(get_dist_path):
|
||||
package_path = get_dist_path()
|
||||
if isinstance(package_path, Path) and package_path.exists():
|
||||
return package_path
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
base_dir = Path(__file__).parent.parent.parent
|
||||
static_path = base_dir / "webui" / "dist"
|
||||
if static_path.exists():
|
||||
return static_path
|
||||
return None
|
||||
|
||||
|
||||
def show_access_token():
|
||||
"""显示 WebUI Access Token(供启动时调用)"""
|
||||
try:
|
||||
|
||||
@@ -1,23 +1,44 @@
|
||||
"""独立的 WebUI 服务器 - 运行在 0.0.0.0:8001"""
|
||||
|
||||
import asyncio
|
||||
from uvicorn import Config, Server as UvicornServer
|
||||
|
||||
import asyncio
|
||||
|
||||
from src.common.logger import get_logger
|
||||
from src.config.config import config_manager
|
||||
from src.webui.app import create_app, show_access_token
|
||||
|
||||
logger = get_logger("webui_server")
|
||||
|
||||
|
||||
class _ASGIProxy:
|
||||
def __init__(self, app):
|
||||
self._app = app
|
||||
|
||||
def set_app(self, app) -> None:
|
||||
self._app = app
|
||||
|
||||
async def __call__(self, scope, receive, send):
|
||||
await self._app(scope, receive, send)
|
||||
|
||||
|
||||
class WebUIServer:
|
||||
"""独立的 WebUI 服务器"""
|
||||
|
||||
def __init__(self, host: str = "0.0.0.0", port: int = 8001):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.app = create_app(host=host, port=port, enable_static=True)
|
||||
self._app = create_app(host=host, port=port, enable_static=True)
|
||||
self.app = _ASGIProxy(self._app)
|
||||
self._server = None
|
||||
|
||||
show_access_token()
|
||||
config_manager.register_reload_callback(self.reload_app)
|
||||
|
||||
async def reload_app(self) -> None:
|
||||
self._app = create_app(host=self.host, port=self.port, enable_static=True)
|
||||
self.app.set_app(self._app)
|
||||
logger.info("WebUI 应用已热重载")
|
||||
|
||||
async def start(self):
|
||||
"""启动服务器"""
|
||||
@@ -71,6 +92,8 @@ class WebUIServer:
|
||||
except Exception as e:
|
||||
logger.error(f"❌ WebUI 服务器运行错误: {e}", exc_info=True)
|
||||
raise
|
||||
finally:
|
||||
config_manager.unregister_reload_callback(self.reload_app)
|
||||
|
||||
def _check_port_available(self) -> bool:
|
||||
"""检查端口是否可用(支持 IPv4 和 IPv6)"""
|
||||
|
||||
Reference in New Issue
Block a user