feat(gateway): 新增消息网关及apikey功能
Quality check / Web UI (push) Successful in 9m16s

This commit is contained in:
mei
2026-08-30 21:09:26 +08:00
parent 360169ee64
commit 0d89b7fe8f
18 changed files with 363 additions and 20 deletions
+13
View File
@@ -0,0 +1,13 @@
package model
type MessageGateway struct {
ID uint `gorm:"primaryKey" json:"id"`
UID uint `gorm:"index" json:"uid"`
Name string `json:"name"`
Token string `gorm:"uniqueIndex;size:67" json:"token"`
CreateAt int64 `json:"create_at"`
}
type MessageGatewayRequest struct {
Name string `json:"name"`
}
+11 -6
View File
@@ -2,10 +2,11 @@ package model
// Rule 描述一个 Timer 到期后要执行的动作
type Rule struct {
ID uint `json:"id" gorm:"primaryKey"`
UID uint `gorm:"index" json:"uid"`
TimerID uint `gorm:"index" json:"timer_id"`
Name string `json:"name"`
ID uint `json:"id" gorm:"primaryKey"`
UID uint `gorm:"index" json:"uid"`
TimerID uint `gorm:"index" json:"timer_id"`
GatewayID uint `gorm:"index" json:"gateway_id"`
Name string `json:"name"`
// 关联账号,部分规则类型(如钉钉)不需要账号,此时为 0
AccountID uint `json:"account_id"`
// 规则类型,见 internal/ruleConfigChecker 注册表
@@ -20,6 +21,7 @@ type Rule struct {
type RuleRequest struct {
Name string `json:"name"`
TimerID uint `json:"timer_id"`
GatewayID uint `json:"gateway_id"`
AccountID uint `json:"account_id"`
Type string `json:"type"`
ConfigJson string `json:"config_json"`
@@ -37,8 +39,11 @@ func (r *RuleRequest) Validate() error {
if r.Type == "" {
return ErrValidation("规则类型不能为空")
}
if r.TimerID == 0 {
return ErrValidation("必须关联一个 Timer")
if r.TimerID == 0 && r.GatewayID == 0 {
return ErrValidation("必须关联一个定时器或消息网关")
}
if r.TimerID != 0 && r.GatewayID != 0 {
return ErrValidation("定时器和消息网关只能选择一个")
}
if r.ConfigJson == "" {
return ErrValidation("规则配置不能为空")
+1
View File
@@ -23,6 +23,7 @@ type User struct {
CreateAt int64 `json:"create_at"`
Username string `gorm:"uniqueIndex" json:"username"`
Password string `json:"-"`
APIKey string `gorm:"index;size:67" json:"api_key"`
// 管理员可以修改系统配置。第一个注册的用户自动成为管理员。
IsAdmin bool `gorm:"default:false" json:"is_admin"`
// 钉钉机器人配置(JSON 字符串),用于接收提醒