换成单集群模式

This commit is contained in:
robin
2026-03-02 20:07:53 +08:00
parent 5d0b7c7e91
commit 2a76d1773d
432 changed files with 5681 additions and 5095 deletions

View File

@@ -1,6 +1,8 @@
package models
import (
"encoding/json"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
@@ -35,12 +37,17 @@ func init() {
})
}
func (this *HTTPDNSAppDAO) CreateApp(tx *dbs.Tx, name string, appId string, primaryClusterId int64, backupClusterId int64, isOn bool, userId int64) (int64, error) {
func (this *HTTPDNSAppDAO) CreateApp(tx *dbs.Tx, name string, appId string, clusterIdsJSON []byte, isOn bool, userId int64) (int64, error) {
var op = NewHTTPDNSAppOperator()
op.Name = name
op.AppId = appId
op.PrimaryClusterId = primaryClusterId
op.BackupClusterId = backupClusterId
if len(clusterIdsJSON) > 0 {
op.ClusterIdsJSON = string(clusterIdsJSON)
} else {
op.ClusterIdsJSON = "[]"
}
op.IsOn = isOn
op.UserId = userId
op.SNIMode = HTTPDNSSNIModeFixedHide
@@ -54,18 +61,37 @@ func (this *HTTPDNSAppDAO) CreateApp(tx *dbs.Tx, name string, appId string, prim
return types.Int64(op.Id), nil
}
func (this *HTTPDNSAppDAO) UpdateApp(tx *dbs.Tx, appDbId int64, name string, primaryClusterId int64, backupClusterId int64, isOn bool, userId int64) error {
func (this *HTTPDNSAppDAO) UpdateApp(tx *dbs.Tx, appDbId int64, name string, clusterIdsJSON []byte, isOn bool, userId int64) error {
var op = NewHTTPDNSAppOperator()
op.Id = appDbId
op.Name = name
op.PrimaryClusterId = primaryClusterId
op.BackupClusterId = backupClusterId
if len(clusterIdsJSON) > 0 {
op.ClusterIdsJSON = string(clusterIdsJSON)
} else {
op.ClusterIdsJSON = "[]"
}
op.IsOn = isOn
op.UserId = userId
op.UpdatedAt = time.Now().Unix()
return this.Save(tx, op)
}
// ReadAppClusterIds reads cluster IDs from ClusterIdsJSON.
func (this *HTTPDNSAppDAO) ReadAppClusterIds(app *HTTPDNSApp) []int64 {
if app == nil {
return nil
}
if len(app.ClusterIdsJSON) > 0 {
var ids []int64
if err := json.Unmarshal([]byte(app.ClusterIdsJSON), &ids); err == nil && len(ids) > 0 {
return ids
}
}
return nil
}
func (this *HTTPDNSAppDAO) DisableApp(tx *dbs.Tx, appDbId int64) error {
_, err := this.Query(tx).
Pk(appDbId).

View File

@@ -6,8 +6,7 @@ type HTTPDNSApp struct {
Name string `field:"name"` // app name
AppId string `field:"appId"` // external app id
IsOn bool `field:"isOn"` // enabled
PrimaryClusterId uint32 `field:"primaryClusterId"` // primary cluster id
BackupClusterId uint32 `field:"backupClusterId"` // backup cluster id
ClusterIdsJSON string `field:"clusterIdsJSON"` // cluster ids json
SNIMode string `field:"sniMode"` // sni mode
UserId int64 `field:"userId"` // owner user id
CreatedAt uint64 `field:"createdAt"` // created unix ts
@@ -21,8 +20,7 @@ type HTTPDNSAppOperator struct {
Name any // app name
AppId any // external app id
IsOn any // enabled
PrimaryClusterId any // primary cluster id
BackupClusterId any // backup cluster id
ClusterIdsJSON any // cluster ids json
SNIMode any // sni mode
UserId any // owner user id
CreatedAt any // created unix ts

View File

@@ -246,7 +246,7 @@ func (this *UserDAO) CreateUser(tx *dbs.Tx, username string,
}
// UpdateUser 修改用户
func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, password string, fullname string, mobile string, tel string, email string, remark string, isOn bool, nodeClusterId int64, bandwidthAlgo systemconfigs.BandwidthAlgo) error {
func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, password string, fullname string, mobile string, tel string, email string, remark string, isOn bool, nodeClusterId int64, bandwidthAlgo systemconfigs.BandwidthAlgo, httpdnsClusterIdsJSON []byte) error {
if userId <= 0 {
return errors.New("invalid userId")
}
@@ -265,6 +265,11 @@ func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, passw
op.ClusterId = nodeClusterId
op.BandwidthAlgo = bandwidthAlgo
op.IsOn = isOn
if len(httpdnsClusterIdsJSON) > 0 {
op.HttpdnsClusterIds = string(httpdnsClusterIdsJSON)
} else {
op.HttpdnsClusterIds = "[]"
}
err := this.Save(tx, op)
if err != nil {
return err
@@ -466,6 +471,21 @@ func (this *UserDAO) FindUserClusterId(tx *dbs.Tx, userId int64) (int64, error)
FindInt64Col(0)
}
// UpdateUserHttpdnsClusterIds 更新用户的HTTPDNS关联集群ID列表
func (this *UserDAO) UpdateUserHttpdnsClusterIds(tx *dbs.Tx, userId int64, httpdnsClusterIdsJSON []byte) error {
if userId <= 0 {
return errors.New("invalid userId")
}
if len(httpdnsClusterIdsJSON) == 0 {
httpdnsClusterIdsJSON = []byte("[]")
}
_, err := this.Query(tx).
Pk(userId).
Set("httpdnsClusterIds", httpdnsClusterIdsJSON).
Update()
return err
}
// UpdateUserFeatures 更新单个用户Features
func (this *UserDAO) UpdateUserFeatures(tx *dbs.Tx, userId int64, featuresJSON []byte) error {
if userId <= 0 {

View File

@@ -37,6 +37,7 @@ const (
UserField_BandwidthAlgo dbs.FieldName = "bandwidthAlgo" // 带宽算法
UserField_BandwidthModifier dbs.FieldName = "bandwidthModifier" // 带宽修正值
UserField_Lang dbs.FieldName = "lang" // 语言代号
UserField_HttpdnsClusterIds dbs.FieldName = "httpdnsClusterIds" // HTTPDNS关联集群ID列表
)
// User 用户
@@ -75,6 +76,7 @@ type User struct {
BandwidthAlgo string `field:"bandwidthAlgo"` // 带宽算法
BandwidthModifier float64 `field:"bandwidthModifier"` // 带宽修正值
Lang string `field:"lang"` // 语言代号
HttpdnsClusterIds dbs.JSON `field:"httpdnsClusterIds"` // HTTPDNS关联集群ID列表
}
type UserOperator struct {
@@ -112,6 +114,7 @@ type UserOperator struct {
BandwidthAlgo any // 带宽算法
BandwidthModifier any // 带宽修正值
Lang any // 语言代号
HttpdnsClusterIds any // HTTPDNS关联集群ID列表
}
func NewUserOperator() *UserOperator {