mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-05 03:30:25 +08:00
创建或修改服务域名时检查域名是否重复
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateAction struct {
|
type CreateAction struct {
|
||||||
@@ -215,6 +216,22 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("域名解析失败:" + err.Error())
|
this.Fail("域名解析失败:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查域名是否已经存在
|
||||||
|
allServerNames := serverconfigs.PlainServerNames(serverNames)
|
||||||
|
if len(allServerNames) > 0 {
|
||||||
|
dupResp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{
|
||||||
|
ServerNames: allServerNames,
|
||||||
|
NodeClusterId: params.ClusterId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(dupResp.DuplicatedServerNames) > 0 {
|
||||||
|
this.Fail("域名 " + strings.Join(dupResp.DuplicatedServerNames, ", ") + " 已经被其他服务所占用,不能重复使用")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 源站地址
|
// 源站地址
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 域名管理
|
// 域名管理
|
||||||
@@ -74,6 +75,34 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
this.Fail("域名解析失败:" + err.Error())
|
this.Fail("域名解析失败:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: params.ServerId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if serverResp.Server == nil || serverResp.Server.NodeCluster == nil {
|
||||||
|
this.NotFound("server", params.ServerId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clusterId := serverResp.Server.NodeCluster.Id
|
||||||
|
|
||||||
|
// 检查域名是否已经存在
|
||||||
|
allServerNames := serverconfigs.PlainServerNames(serverNames)
|
||||||
|
if len(allServerNames) > 0 {
|
||||||
|
dupResp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{
|
||||||
|
ServerNames: allServerNames,
|
||||||
|
NodeClusterId: clusterId,
|
||||||
|
ExcludeServerId: params.ServerId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(dupResp.DuplicatedServerNames) > 0 {
|
||||||
|
this.Fail("域名 " + strings.Join(dupResp.DuplicatedServerNames, ", ") + " 已经被其他服务所占用,不能重复使用")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_, err = this.RPC().ServerRPC().UpdateServerNames(this.AdminContext(), &pb.UpdateServerNamesRequest{
|
_, err = this.RPC().ServerRPC().UpdateServerNames(this.AdminContext(), &pb.UpdateServerNamesRequest{
|
||||||
ServerId: params.ServerId,
|
ServerId: params.ServerId,
|
||||||
ServerNamesJSON: []byte(params.ServerNames),
|
ServerNamesJSON: []byte(params.ServerNames),
|
||||||
|
|||||||
Reference in New Issue
Block a user