MCPcopy Create free account
hub / github.com/ShukeBta/MediaStationGo / Create

Method Create

internal/handler/notify_handler.go:44–84  ·  view source on GitHub ↗

Create 创建新的通知渠道。

(c *gin.Context)

Source from the content-addressed store, hash-verified

42
43// Create 创建新的通知渠道。
44func (h *NotifyHandler) Create(c *gin.Context) {
45 var req notifyCreateRequest
46 if err := c.ShouldBindJSON(&req); err != nil {
47 Error(c, http.StatusBadRequest, ErrInvalidParams, err.Error())
48 return
49 }
50
51 ctx := c.Request.Context()
52
53 // 验证配置
54 if err := h.svc.Notify.ValidateChannelConfig(req.Type, req.Config); err != nil {
55 Error(c, http.StatusBadRequest, ErrInvalidParams, "配置验证失败: "+err.Error())
56 return
57 }
58
59 // 加密配置
60 configJSON, _ := json.Marshal(req.Config)
61 configStr := string(configJSON)
62 if h.svc.Crypto != nil {
63 configStr = h.svc.Crypto.Encrypt(configStr)
64 }
65
66 // 序列化事件列表
67 eventsJSON, _ := json.Marshal(req.Events)
68 eventsStr := string(eventsJSON)
69
70 channel := &model.NotifyChannel{
71 Name: req.Name,
72 Type: req.Type,
73 Enabled: req.Enabled,
74 Config: configStr,
75 Events: eventsStr,
76 }
77
78 if err := h.svc.Repo.NotifyChannel.Create(ctx, channel); err != nil {
79 Error(c, http.StatusInternalServerError, ErrInternal, "创建失败: "+err.Error())
80 return
81 }
82
83 Success(c, channel)
84}
85
86// List 返回所有通知渠道。
87func (h *NotifyHandler) List(c *gin.Context) {

Calls 6

ErrorFunction · 0.85
SuccessFunction · 0.85
ContextMethod · 0.80
ValidateChannelConfigMethod · 0.80
EncryptMethod · 0.80
ErrorMethod · 0.45