nezha/model/server.go

57 lines
1.8 KiB
Go
Raw Permalink Normal View History

2019-12-08 23:18:29 +08:00
package model
2019-12-10 17:57:57 +08:00
import (
"log"
2020-10-24 21:29:05 +08:00
"time"
2024-10-20 00:32:55 +08:00
"gorm.io/gorm"
2024-11-28 19:38:54 +08:00
"github.com/nezhahq/nezha/pkg/utils"
pb "github.com/nezhahq/nezha/proto"
2019-12-10 17:57:57 +08:00
)
2019-12-08 23:18:29 +08:00
type Server struct {
Common
2024-11-16 20:57:03 +08:00
Name string `json:"name"`
2024-10-20 23:23:04 +08:00
UUID string `json:"uuid,omitempty" gorm:"unique"`
Note string `json:"note,omitempty"` // 管理员可见备注
PublicNote string `json:"public_note,omitempty"` // 公开备注
2024-11-16 20:57:03 +08:00
DisplayIndex int `json:"display_index"` // 展示排序,越大越靠前
2024-10-20 23:23:04 +08:00
HideForGuest bool `json:"hide_for_guest,omitempty"` // 对游客隐藏
EnableDDNS bool `json:"enable_ddns,omitempty"` // 启用DDNS
DDNSProfilesRaw string `gorm:"default:'[]';column:ddns_profiles_raw" json:"-"`
2021-01-17 22:05:59 +08:00
2024-11-28 17:06:54 +08:00
DDNSProfiles []uint64 `gorm:"-" json:"ddns_profiles,omitempty" validate:"optional"` // DDNS配置
2024-10-20 23:23:04 +08:00
Host *Host `gorm:"-" json:"host,omitempty"`
State *HostState `gorm:"-" json:"state,omitempty"`
GeoIP *GeoIP `gorm:"-" json:"geoip,omitempty"`
2024-10-20 23:23:04 +08:00
LastActive time.Time `gorm:"-" json:"last_active,omitempty"`
2019-12-10 17:57:57 +08:00
2024-12-05 00:11:34 +08:00
TaskStream pb.NezhaService_RequestTaskServer `gorm:"-" json:"-"`
PrevTransferInSnapshot int64 `gorm:"-" json:"-"` // 上次数据点时的入站使用量
PrevTransferOutSnapshot int64 `gorm:"-" json:"-"` // 上次数据点时的出站使用量
2019-12-08 23:18:29 +08:00
}
2020-12-09 10:27:00 +08:00
func (s *Server) CopyFromRunningServer(old *Server) {
s.Host = old.Host
s.State = old.State
s.GeoIP = old.GeoIP
s.LastActive = old.LastActive
s.TaskStream = old.TaskStream
s.PrevTransferInSnapshot = old.PrevTransferInSnapshot
s.PrevTransferOutSnapshot = old.PrevTransferOutSnapshot
}
func (s *Server) AfterFind(tx *gorm.DB) error {
if s.DDNSProfilesRaw != "" {
if err := utils.Json.Unmarshal([]byte(s.DDNSProfilesRaw), &s.DDNSProfiles); err != nil {
log.Println("NEZHA>> Server.AfterFind:", err)
return nil
}
}
return nil
}