修复webhook url指定

This commit is contained in:
2025-10-29 12:14:50 +08:00
parent d36bb2de83
commit c80fb67165
2 changed files with 12 additions and 13 deletions

10
app.py
View File

@@ -7,7 +7,7 @@ from fastapi.responses import JSONResponse
from contextlib import asynccontextmanager
import asyncio
from config import APP_CONFIG, SESSION_TIMEOUT
from config import APP_CONFIG, SESSION_TIMEOUT, SetWebhookURL, GetWebhookURL
from core.middleware import ConcurrencyLimitMiddleware
from core.database import get_db
from routers import callback, health
@@ -125,15 +125,9 @@ if __name__ == "__main__":
# 如果提供了webhook URL设置环境变量
if args.webhook_url:
os.environ['WEBHOOK_URL'] = args.webhook_url
SetWebhookURL(args.webhook_url)
logger.info(f"设置Webhook URL: {args.webhook_url}")
# 重新导入配置模块以更新WEBHOOK_URL
import importlib
import config
importlib.reload(config)
logger.info(f"更新后的Webhook URL: {config.WEBHOOK_URL}")
# 启动服务器
uvicorn.run(
"app:app",

View File

@@ -9,15 +9,20 @@ load_dotenv()
# 项目根目录
BASE_DIR = Path(__file__).resolve().parent
def get_webhook_url():
"""动态获取Webhook URL"""
return os.getenv(
# WPS Webhook配置 - 使用函数动态获取
WEBHOOK_URL = os.getenv(
"WEBHOOK_URL",
"https://xz.wps.cn/api/v1/webhook/send?key=da86927e491f2aef4b964223687c2c80"
)
# WPS Webhook配置 - 使用函数动态获取
WEBHOOK_URL = get_webhook_url()
def SetWebhookURL(url: str):
"""设置Webhook URL"""
global WEBHOOK_URL
WEBHOOK_URL = url
def GetWebhookURL() -> str:
"""获取Webhook URL"""
return WEBHOOK_URL
# 数据库配置
DATABASE_PATH = os.getenv("DATABASE_PATH", str(BASE_DIR / "data" / "bot.db"))