2024-10-17 09:03:03 -04:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2024-10-25 20:16:57 -04:00
|
|
|
"github.com/naiba/nezha/pkg/utils"
|
2024-10-17 09:03:03 -04:00
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-10-21 12:04:17 -04:00
|
|
|
ProviderDummy = "dummy"
|
|
|
|
ProviderWebHook = "webhook"
|
|
|
|
ProviderCloudflare = "cloudflare"
|
|
|
|
ProviderTencentCloud = "tencentcloud"
|
2024-10-17 09:03:03 -04:00
|
|
|
)
|
|
|
|
|
2024-10-21 12:04:17 -04:00
|
|
|
var ProviderList = []string{
|
|
|
|
ProviderDummy, ProviderWebHook, ProviderCloudflare, ProviderTencentCloud,
|
2024-10-17 09:03:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type DDNSProfile struct {
|
|
|
|
Common
|
2024-10-21 12:04:17 -04:00
|
|
|
EnableIPv4 *bool `json:"enable_ipv4,omitempty"`
|
|
|
|
EnableIPv6 *bool `json:"enable_ipv6,omitempty"`
|
2024-11-16 07:57:03 -05:00
|
|
|
MaxRetries uint64 `json:"max_retries"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Provider string `json:"provider"`
|
2024-10-21 12:04:17 -04:00
|
|
|
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"`
|
2024-11-16 07:57:03 -05:00
|
|
|
Domains []string `json:"domains" gorm:"-"`
|
2024-10-25 20:16:57 -04:00
|
|
|
DomainsRaw string `json:"-"`
|
2024-10-17 09:03:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d DDNSProfile) TableName() string {
|
|
|
|
return "ddns"
|
|
|
|
}
|
|
|
|
|
2024-10-25 20:16:57 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-10-17 09:03:03 -04:00
|
|
|
func (d *DDNSProfile) AfterFind(tx *gorm.DB) error {
|
|
|
|
if d.DomainsRaw != "" {
|
|
|
|
d.Domains = strings.Split(d.DomainsRaw, ",")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|