diff --git a/src/api/main.py b/src/api/main.py index e8d2054f1..be2259404 100644 --- a/src/api/main.py +++ b/src/api/main.py @@ -1,5 +1,6 @@ from fastapi import APIRouter from strawberry.fastapi import GraphQLRouter + # from src.config.config import BotConfig from src.common.logger_manager import get_logger from src.api.reload_config import reload_config as reload_config_func @@ -18,11 +19,12 @@ graphql_router = GraphQLRouter(schema=None, path="/") # Replace `None` with you router.include_router(graphql_router, prefix="/graphql", tags=["GraphQL"]) + @router.post("/config/reload") async def reload_config(): return await reload_config_func() + def start_api_server(): """启动API服务器""" - global_server.register_router(router, prefix="/api/v1") - + global_server.register_router(router, prefix="/api/v1") diff --git a/src/api/reload_config.py b/src/api/reload_config.py index 33a02e731..d77cb536b 100644 --- a/src/api/reload_config.py +++ b/src/api/reload_config.py @@ -2,17 +2,18 @@ from fastapi import HTTPException from rich.traceback import install from src.config.config import BotConfig import os -install(extra_lines=3) +install(extra_lines=3) async def reload_config(): try: from src.config import config as config_module + bot_config_path = os.path.join(BotConfig.get_config_dir(), "bot_config.toml") config_module.global_config = BotConfig.load_config(config_path=bot_config_path) return {"status": "reloaded"} except FileNotFoundError as e: raise HTTPException(status_code=404, detail=str(e)) from e except Exception as e: - raise HTTPException(status_code=500, detail=f"重载配置时发生错误: {str(e)}") from e \ No newline at end of file + raise HTTPException(status_code=500, detail=f"重载配置时发生错误: {str(e)}") from e diff --git a/src/common/logger.py b/src/common/logger.py index 432b1bdca..88fc427f2 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -894,9 +894,8 @@ CHAT_MESSAGE_STYLE_CONFIG = ( ) CHAT_IMAGE_STYLE_CONFIG = CHAT_IMAGE_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else CHAT_IMAGE_STYLE_CONFIG["advanced"] INIT_STYLE_CONFIG = INIT_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else INIT_STYLE_CONFIG["advanced"] -API_SERVER_STYLE_CONFIG = ( - API_SERVER_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else API_SERVER_STYLE_CONFIG["advanced"] -) +API_SERVER_STYLE_CONFIG = API_SERVER_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else API_SERVER_STYLE_CONFIG["advanced"] + def is_registered_module(record: dict) -> bool: """检查是否为已注册的模块"""