2019-12-08 10:18:29 -05:00
|
|
|
package model
|
|
|
|
|
2019-12-10 04:57:57 -05:00
|
|
|
import (
|
2024-10-17 09:03:03 -04:00
|
|
|
"log"
|
2024-08-11 22:06:55 -04:00
|
|
|
"sync"
|
2020-10-24 09:29:05 -04:00
|
|
|
"time"
|
|
|
|
|
2024-10-19 12:32:55 -04:00
|
|
|
"gorm.io/gorm"
|
|
|
|
|
2022-03-18 11:13:22 -04:00
|
|
|
"github.com/naiba/nezha/pkg/utils"
|
2020-11-10 21:07:45 -05:00
|
|
|
pb "github.com/naiba/nezha/proto"
|
2019-12-10 04:57:57 -05:00
|
|
|
)
|
|
|
|
|
2019-12-08 10:18:29 -05:00
|
|
|
type Server struct {
|
|
|
|
Common
|
2024-10-17 09:03:03 -04:00
|
|
|
|
2024-10-20 11:23:04 -04:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
UUID string `json:"uuid,omitempty" gorm:"unique"`
|
|
|
|
Note string `json:"note,omitempty"` // 管理员可见备注
|
|
|
|
PublicNote string `json:"public_note,omitempty"` // 公开备注
|
|
|
|
DisplayIndex int `json:"display_index,omitempty"` // 展示排序,越大越靠前
|
|
|
|
HideForGuest bool `json:"hide_for_guest,omitempty"` // 对游客隐藏
|
|
|
|
EnableDDNS bool `json:"enable_ddns,omitempty"` // 启用DDNS
|
2024-10-17 09:03:03 -04:00
|
|
|
DDNSProfilesRaw string `gorm:"default:'[]';column:ddns_profiles_raw" json:"-"`
|
2021-01-17 09:05:59 -05:00
|
|
|
|
2024-10-20 11:23:04 -04:00
|
|
|
DDNSProfiles []uint64 `gorm:"-" json:"ddns_profiles,omitempty"` // DDNS配置
|
|
|
|
|
|
|
|
Host *Host `gorm:"-" json:"host,omitempty"`
|
|
|
|
State *HostState `gorm:"-" json:"state,omitempty"`
|
|
|
|
LastActive time.Time `gorm:"-" json:"last_active,omitempty"`
|
2019-12-10 04:57:57 -05:00
|
|
|
|
2024-08-11 22:06:55 -04:00
|
|
|
TaskClose chan error `gorm:"-" json:"-"`
|
|
|
|
TaskCloseLock *sync.Mutex `gorm:"-" json:"-"`
|
|
|
|
TaskStream pb.NezhaService_RequestTaskServer `gorm:"-" json:"-"`
|
2021-07-14 11:53:37 -04:00
|
|
|
|
2024-08-10 22:35:19 -04:00
|
|
|
PrevTransferInSnapshot int64 `gorm:"-" json:"-"` // 上次数据点时的入站使用量
|
|
|
|
PrevTransferOutSnapshot int64 `gorm:"-" json:"-"` // 上次数据点时的出站使用量
|
2019-12-08 10:18:29 -05:00
|
|
|
}
|
2020-12-08 21:27:00 -05:00
|
|
|
|
2021-07-25 11:50:08 -04:00
|
|
|
func (s *Server) CopyFromRunningServer(old *Server) {
|
|
|
|
s.Host = old.Host
|
|
|
|
s.State = old.State
|
|
|
|
s.LastActive = old.LastActive
|
|
|
|
s.TaskClose = old.TaskClose
|
2024-08-11 22:06:55 -04:00
|
|
|
s.TaskCloseLock = old.TaskCloseLock
|
2021-07-25 11:50:08 -04:00
|
|
|
s.TaskStream = old.TaskStream
|
2024-08-10 22:35:19 -04:00
|
|
|
s.PrevTransferInSnapshot = old.PrevTransferInSnapshot
|
|
|
|
s.PrevTransferOutSnapshot = old.PrevTransferOutSnapshot
|
2021-07-25 11:50:08 -04:00
|
|
|
}
|
|
|
|
|
2024-10-17 09:03:03 -04:00
|
|
|
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
|
|
|
|
}
|