1.4.5.2
This commit is contained in:
122
EdgeUser/internal/web/actions/default/ns/domains/update.go
Normal file
122
EdgeUser/internal/web/actions/default/ns/domains/update.go
Normal file
@@ -0,0 +1,122 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/ns/domains/domainutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateAction) Init() {
|
||||
this.Nav("", "", "update")
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunGet(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
// 初始化域名信息
|
||||
err := domainutils.InitDomain(this.Parent(), params.DomainId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countRecords = this.Data.GetMap("domain").GetInt64("countRecords")
|
||||
var countKeys = this.Data.GetMap("domain").GetInt64("countKeys")
|
||||
|
||||
// 域名信息
|
||||
domainResp, err := this.RPC().NSDomainRPC().FindNSDomain(this.UserContext(), &pb.FindNSDomainRequest{NsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
domain := domainResp.NsDomain
|
||||
if domain == nil {
|
||||
this.NotFound("nsDomain", params.DomainId)
|
||||
return
|
||||
}
|
||||
|
||||
var clusterId = int64(0)
|
||||
if domain.NsCluster != nil {
|
||||
clusterId = domain.NsCluster.Id
|
||||
}
|
||||
|
||||
// 用户信息
|
||||
var userId = int64(0)
|
||||
if domain.User != nil {
|
||||
userId = domain.User.Id
|
||||
}
|
||||
|
||||
// 分组信息
|
||||
var groupId int64
|
||||
if len(domain.NsDomainGroups) > 0 {
|
||||
groupId = domain.NsDomainGroups[0].Id
|
||||
}
|
||||
|
||||
this.Data["domain"] = maps.Map{
|
||||
"id": domain.Id,
|
||||
"name": domain.Name,
|
||||
"isOn": domain.IsOn,
|
||||
"clusterId": clusterId,
|
||||
"userId": userId,
|
||||
"countRecords": countRecords,
|
||||
"countKeys": countKeys,
|
||||
"groupId": groupId,
|
||||
}
|
||||
|
||||
// DNS服务器
|
||||
if domain.NsCluster == nil || domain.NsCluster.Id <= 0 {
|
||||
this.WriteString("当前域名(" + domain.Name + ")所在集群已被删除,请删除当前域名后重新添加")
|
||||
return
|
||||
}
|
||||
|
||||
hostsResp, err := this.RPC().NSClusterRPC().FindNSClusterHosts(this.UserContext(), &pb.FindNSClusterHostsRequest{
|
||||
NsClusterId: domain.NsCluster.Id,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var hosts = hostsResp.Hosts
|
||||
if hosts == nil {
|
||||
hosts = []string{}
|
||||
}
|
||||
this.Data["dnsHosts"] = hosts
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
DomainId int64
|
||||
GroupId int64
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSDomain_LogUpdateNSDomain, params.DomainId)
|
||||
|
||||
var groupIds = []int64{}
|
||||
if params.GroupId > 0 {
|
||||
groupIds = append(groupIds, params.GroupId)
|
||||
}
|
||||
|
||||
_, err := this.RPC().NSDomainRPC().UpdateNSDomain(this.UserContext(), &pb.UpdateNSDomainRequest{
|
||||
NsDomainId: params.DomainId,
|
||||
NsDomainGroupIds: groupIds,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user