first commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""通知相关 API(需鉴权)。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from apps.api.auth import require_auth
|
||||
from packages.notify import wecom
|
||||
|
||||
router = APIRouter(prefix="/notify", tags=["notify"], dependencies=[Depends(require_auth)])
|
||||
|
||||
|
||||
@router.get("/wecom/status")
|
||||
def wecom_status() -> dict:
|
||||
url = wecom.wecom_webhook_url()
|
||||
masked = None
|
||||
if url:
|
||||
if len(url) > 24:
|
||||
masked = url[:18] + "…" + url[-6:]
|
||||
else:
|
||||
masked = "***"
|
||||
return {
|
||||
"enabled": wecom.wecom_enabled(),
|
||||
"webhook_configured": bool(url),
|
||||
"webhook_url_masked": masked,
|
||||
"machine_name": wecom.wecom_machine_name(),
|
||||
"alert_fail_threshold": wecom.alert_fail_threshold(),
|
||||
}
|
||||
|
||||
|
||||
@router.post("/wecom/test")
|
||||
def wecom_test() -> dict:
|
||||
ok, msg = wecom.notify_test()
|
||||
return {"ok": ok, "message": msg}
|
||||
Reference in New Issue
Block a user