add alert api (#458)

This commit is contained in:
UUBulb
2024-10-26 08:16:57 +08:00
committed by GitHub
parent 8c452bdaa9
commit ebc4fad9bc
10 changed files with 278 additions and 78 deletions

View File

@@ -3,6 +3,7 @@ package model
import (
"strings"
"github.com/naiba/nezha/pkg/utils"
"gorm.io/gorm"
)
@@ -32,33 +33,25 @@ type DDNSProfile struct {
WebhookRequestBody string `json:"webhook_request_body,omitempty"`
WebhookHeaders string `json:"webhook_headers,omitempty"`
Domains []string `json:"domains,omitempty" gorm:"-"`
DomainsRaw string `json:"domains_raw,omitempty"`
DomainsRaw string `json:"-"`
}
func (d DDNSProfile) TableName() string {
return "ddns"
}
func (d *DDNSProfile) BeforeSave(tx *gorm.DB) error {
if data, err := utils.Json.Marshal(d.Domains); err != nil {
return err
} else {
d.DomainsRaw = string(data)
}
return nil
}
func (d *DDNSProfile) AfterFind(tx *gorm.DB) error {
if d.DomainsRaw != "" {
d.Domains = strings.Split(d.DomainsRaw, ",")
}
return nil
}
type DDNSForm struct {
ID uint64 `json:"id,omitempty"`
MaxRetries uint64 `json:"max_retries,omitempty"`
EnableIPv4 bool `json:"enable_ipv4,omitempty"`
EnableIPv6 bool `json:"enable_ipv6,omitempty"`
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
DomainsRaw string `json:"domains_raw,omitempty"`
AccessID string `json:"access_id,omitempty"`
AccessSecret string `json:"access_secret,omitempty"`
WebhookURL string `json:"webhook_url,omitempty"`
WebhookMethod uint8 `json:"webhook_method,omitempty"`
WebhookRequestType uint8 `json:"webhook_request_type,omitempty"`
WebhookRequestBody string `json:"webhook_request_body,omitempty"`
WebhookHeaders string `json:"webhook_headers,omitempty"`
}