From c805b9a8b4003db77db69be0a17f528944d58a89 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Fri, 25 Aug 2023 17:28:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8D=95=E4=B8=AA=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=90=8C=E5=B1=9E=E5=A4=9A=E4=B8=AA=E9=9B=86=E7=BE=A4?= =?UTF-8?q?=E6=97=B6DNS=E7=BA=BF=E8=B7=AF=E8=AE=BE=E7=BD=AE=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=A4=8D=E5=88=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cluster/node/settings/dns/index.go | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/internal/web/actions/default/clusters/cluster/node/settings/dns/index.go b/internal/web/actions/default/clusters/cluster/node/settings/dns/index.go index 824a5159..a0a367f8 100644 --- a/internal/web/actions/default/clusters/cluster/node/settings/dns/index.go +++ b/internal/web/actions/default/clusters/cluster/node/settings/dns/index.go @@ -9,6 +9,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/maps" ) @@ -35,6 +36,7 @@ func (this *IndexAction) RunGet(params struct { clusters = append(clusters, node.SecondaryNodeClusters...) var allDNSRouteMaps = map[int64][]maps.Map{} // domain id => routes var routeMaps = map[int64][]maps.Map{} // domain id => routes + var domainIds = []int64{} for _, cluster := range clusters { dnsInfoResp, err := this.RPC().NodeRPC().FindEnabledNodeDNS(this.AdminContext(), &pb.FindEnabledNodeDNSRequest{ NodeId: params.NodeId, @@ -49,6 +51,13 @@ func (this *IndexAction) RunGet(params struct { continue } var domainId = dnsInfo.DnsDomainId + + // remove same domain + if lists.ContainsInt64(domainIds, domainId) { + continue + } + domainIds = append(domainIds, domainId) + var domainName = dnsInfo.DnsDomainName if len(dnsInfo.Routes) > 0 { for _, route := range dnsInfo.Routes { @@ -102,15 +111,23 @@ func (this *IndexAction) RunPost(params struct { }) { defer this.CreateLogInfo(codes.NodeDNS_LogUpdateNodeDNS, params.NodeId) - dnsRouteCodes := []string{} + var rawRouteCodes = []string{} if len(params.DnsRoutesJSON) > 0 { - err := json.Unmarshal(params.DnsRoutesJSON, &dnsRouteCodes) + err := json.Unmarshal(params.DnsRoutesJSON, &rawRouteCodes) if err != nil { this.ErrorPage(err) return } } + // remove duplications + var dnsRouteCodes = []string{} + for _, routeCode := range rawRouteCodes { + if !lists.ContainsString(dnsRouteCodes, routeCode) { + dnsRouteCodes = append(dnsRouteCodes, routeCode) + } + } + _, err := this.RPC().NodeRPC().UpdateNodeDNS(this.AdminContext(), &pb.UpdateNodeDNSRequest{ NodeId: params.NodeId, IpAddr: "",