package controller import ( "encoding/json" "net/http" "github.com/mhsanaei/3x-ui/v3/internal/web/entity" "github.com/mhsanaei/3x-ui/v3/internal/web/service/probenotify" "github.com/gin-gonic/gin" ) // Item 7 B6: the notification settings surface — the notify_* block // (offline grace, traffic step, expiry window, login alerts, the // webhook channel and the two message templates) and a test send. // Like the rest of the probe surfaces these endpoints answer in the // panel's Msg envelope and take effect immediately; validation // refusals are operator-facing text, shown verbatim. (The cf-probe // retirement coverage card that originally rode this payload was // removed in V2.0.1 ⑥ — the checklist lives in the operator docs.) type ProbeNotifyController struct{} func NewProbeNotifyController(g *gin.RouterGroup) *ProbeNotifyController { pc := &ProbeNotifyController{} g.GET("/probe/notify", pc.get) g.PUT("/probe/notify", pc.put) g.POST("/probe/notify/test", pc.test) return pc } type probeNotifyPayload struct { Settings probenotify.SettingsView `json:"settings"` } func (pc *ProbeNotifyController) get(c *gin.Context) { jsonObj(c, probeNotifyPayload{ Settings: probenotify.GetSettings(), }, nil) } func (pc *ProbeNotifyController) put(c *gin.Context) { var body map[string]json.RawMessage if err := c.ShouldBindJSON(&body); err != nil { c.JSON(http.StatusOK, entity.Msg{Success: false, Msg: "请求格式不对"}) return } if err := probenotify.SaveSettings(body); err != nil { // SaveSettings validates everything before writing anything; // its errors are the operator's answer (a range, a malformed // header block), not machine faults. c.JSON(http.StatusOK, entity.Msg{Success: false, Msg: err.Error()}) return } // Answer with the fresh view, like the GET: the tab re-renders // the channel status and secret-set flags from it. jsonObj(c, probeNotifyPayload{ Settings: probenotify.GetSettings(), }, nil) } func (pc *ProbeNotifyController) test(c *gin.Context) { sent, err := probenotify.Test() if err != nil { c.JSON(http.StatusOK, entity.Msg{Success: false, Msg: err.Error()}) return } jsonObj(c, gin.H{"sent": sent}, nil) }