EdgeDNS支持内置线路

This commit is contained in:
刘祥超
2021-08-09 13:56:11 +08:00
parent a256a7328e
commit 69c1d35406
10 changed files with 138 additions and 81 deletions

View File

@@ -4,8 +4,10 @@ package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
)
type OptionsAction struct {
@@ -17,6 +19,18 @@ func (this *OptionsAction) RunPost(params struct {
DomainId int64
UserId int64
}) {
var routeMaps = []maps.Map{}
// 默认线路
for _, route := range dnsconfigs.AllDefaultRoutes {
routeMaps = append(routeMaps, maps.Map{
"name": route.Name,
"code": route.Code,
"type": "default",
})
}
// 自定义
routesResp, err := this.RPC().NSRouteRPC().FindAllEnabledNSRoutes(this.AdminContext(), &pb.FindAllEnabledNSRoutesRequest{
NsClusterId: params.ClusterId,
NsDomainId: params.DomainId,
@@ -27,13 +41,45 @@ func (this *OptionsAction) RunPost(params struct {
return
}
routeMaps := []maps.Map{}
for _, route := range routesResp.NsRoutes {
if len(route.Code) == 0 {
route.Code = "id:" + types.String(route.Id)
}
routeMaps = append(routeMaps, maps.Map{
"id": route.Id,
"name": route.Name,
"code": route.Code,
"type": "user",
})
}
// 运营商
for _, route := range dnsconfigs.AllDefaultISPRoutes {
routeMaps = append(routeMaps, maps.Map{
"name": route.Name,
"code": route.Code,
"type": "isp",
})
}
// 中国
for _, route := range dnsconfigs.AllDefaultChinaProvinceRoutes {
routeMaps = append(routeMaps, maps.Map{
"name": route.Name,
"code": route.Code,
"type": "china",
})
}
// 全球
for _, route := range dnsconfigs.AllDefaultWorldRegionRoutes {
routeMaps = append(routeMaps, maps.Map{
"name": route.Name,
"code": route.Code,
"type": "world",
})
}
this.Data["routes"] = routeMaps
this.Success()