feat: 续费提醒告警(Telegram/邮件多渠道+续费检查+每日定时+前端控制)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""通知与续费提醒路由"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from sqlmodel import Session
|
||||
|
||||
from app.core.security import require_api_key
|
||||
from app.database import get_session
|
||||
from app.services import notification_service, renewal_service
|
||||
|
||||
router = APIRouter(prefix="/api/notify", tags=["notify"])
|
||||
|
||||
|
||||
@router.get("/channels", summary="已配置的通知渠道")
|
||||
def channels() -> dict:
|
||||
return {"channels": notification_service.configured_channels()}
|
||||
|
||||
|
||||
@router.post(
|
||||
"/test",
|
||||
summary="测试通知渠道",
|
||||
dependencies=[Depends(require_api_key)],
|
||||
)
|
||||
def test_notify() -> dict:
|
||||
results = notification_service.notify(
|
||||
"✅ 这是一条来自 vps-manager 的测试通知", subject="vps-manager 测试"
|
||||
)
|
||||
return {"notifications": results}
|
||||
|
||||
|
||||
@router.post(
|
||||
"/renewals",
|
||||
summary="检查续费并发送提醒",
|
||||
dependencies=[Depends(require_api_key)],
|
||||
)
|
||||
def check_renewals(
|
||||
threshold: Optional[int] = Query(default=None, description="提醒阈值天数,默认取配置"),
|
||||
send: bool = Query(default=True, description="是否实际发送(false 仅预览)"),
|
||||
session: Session = Depends(get_session),
|
||||
) -> dict:
|
||||
return renewal_service.check_renewals(session, threshold_days=threshold, send=send)
|
||||
Reference in New Issue
Block a user