fix: 修正后端webhook测试逻辑
This commit is contained in:
@@ -29,7 +29,7 @@ from fastapi import APIRouter, Body
|
|||||||
from app.core import Config
|
from app.core import Config
|
||||||
from app.services import System, Notify
|
from app.services import System, Notify
|
||||||
from app.models.schema import *
|
from app.models.schema import *
|
||||||
import uuid
|
from app.models.config import Webhook as WebhookConfig
|
||||||
|
|
||||||
router = APIRouter(prefix="/api/setting", tags=["全局设置"])
|
router = APIRouter(prefix="/api/setting", tags=["全局设置"])
|
||||||
|
|
||||||
@@ -180,31 +180,19 @@ async def reorder_webhook(webhook: WebhookReorderIn = Body(...)) -> OutBase:
|
|||||||
|
|
||||||
|
|
||||||
@router.post(
|
@router.post(
|
||||||
"/webhook/test",
|
"/webhook/test", summary="测试Webhook配置", response_model=OutBase, status_code=200
|
||||||
summary="测试自定义Webhook",
|
|
||||||
response_model=OutBase,
|
|
||||||
status_code=200,
|
|
||||||
)
|
)
|
||||||
async def test_webhook(webhook_data: dict = Body(...)) -> OutBase:
|
async def test_webhook(webhook: WebhookTestIn = Body(...)) -> OutBase:
|
||||||
"""测试自定义Webhook"""
|
"""测试自定义Webhook"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
webhook_config = {
|
webhook_config = WebhookConfig()
|
||||||
"name": webhook_data.get("name", "测试Webhook"),
|
await webhook_config.load(webhook.data.model_dump())
|
||||||
"url": webhook_data.get("url", ""),
|
await Notify.WebhookPush(
|
||||||
"template": webhook_data.get("template", ""),
|
|
||||||
"enabled": True,
|
|
||||||
"headers": webhook_data.get("headers", {}),
|
|
||||||
"method": webhook_data.get("method", "POST"),
|
|
||||||
}
|
|
||||||
|
|
||||||
await Notify.CustomWebhookPush(
|
|
||||||
"AUTO-MAS Webhook测试",
|
"AUTO-MAS Webhook测试",
|
||||||
"这是一条测试消息,如果您收到此消息,说明Webhook配置正确!",
|
"这是一条测试消息,如果您收到此消息,说明Webhook配置正确!",
|
||||||
webhook_config,
|
webhook_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
return OutBase(message="Webhook测试成功")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return OutBase(code=500, status="error", message=f"Webhook测试失败: {str(e)}")
|
return OutBase(code=500, status="error", message=f"Webhook测试失败: {str(e)}")
|
||||||
|
return OutBase()
|
||||||
|
|||||||
@@ -86,10 +86,10 @@ class Webhook_Info(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class Webhook_Data(BaseModel):
|
class Webhook_Data(BaseModel):
|
||||||
url: Optional[str] = Field(default=None, description="Webhook URL")
|
Url: Optional[str] = Field(default=None, description="Webhook URL")
|
||||||
template: Optional[str] = Field(default=None, description="消息模板")
|
Template: Optional[str] = Field(default=None, description="消息模板")
|
||||||
headers: Optional[Dict[str, str]] = Field(default=None, description="自定义请求头")
|
Headers: Optional[Dict[str, str]] = Field(default=None, description="自定义请求头")
|
||||||
method: Optional[Literal["POST", "GET"]] = Field(
|
Method: Optional[Literal["POST", "GET"]] = Field(
|
||||||
default=None, description="请求方法"
|
default=None, description="请求方法"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -664,6 +664,10 @@ class WebhookReorderIn(WebhookInBase):
|
|||||||
indexList: List[str] = Field(..., description="Webhook ID列表, 按新顺序排列")
|
indexList: List[str] = Field(..., description="Webhook ID列表, 按新顺序排列")
|
||||||
|
|
||||||
|
|
||||||
|
class WebhookTestIn(WebhookInBase):
|
||||||
|
data: Webhook = Field(..., description="Webhook配置数据")
|
||||||
|
|
||||||
|
|
||||||
class PlanCreateIn(BaseModel):
|
class PlanCreateIn(BaseModel):
|
||||||
type: Literal["MaaPlan"]
|
type: Literal["MaaPlan"]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user