Initial commit (code only without large binaries)
This commit is contained in:
126
EdgeAdmin/internal/web/actions/default/ns/routes/options.go
Normal file
126
EdgeAdmin/internal/web/actions/default/ns/routes/options.go
Normal file
@@ -0,0 +1,126 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package routes
|
||||
|
||||
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 {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *OptionsAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
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().FindAllNSRoutes(this.AdminContext(), &pb.FindAllNSRoutesRequest{
|
||||
NsClusterId: params.ClusterId,
|
||||
NsDomainId: params.DomainId,
|
||||
UserId: params.UserId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, route := range routesResp.NsRoutes {
|
||||
if len(route.Code) == 0 {
|
||||
route.Code = "id:" + types.String(route.Id)
|
||||
}
|
||||
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "user",
|
||||
})
|
||||
}
|
||||
|
||||
// 运营商
|
||||
this.Data["hasISPRoutes"] = true
|
||||
for _, route := range dnsconfigs.AllDefaultISPRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "isp",
|
||||
})
|
||||
}
|
||||
|
||||
// 中国
|
||||
this.Data["hasChinaProvinceRoutes"] = true
|
||||
for _, route := range dnsconfigs.AllDefaultChinaProvinceRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "china",
|
||||
})
|
||||
}
|
||||
|
||||
// 全球
|
||||
this.Data["hasWorldRegionRoutes"] = true
|
||||
for _, route := range dnsconfigs.AllDefaultWorldRegionRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "world",
|
||||
})
|
||||
}
|
||||
|
||||
// 省份
|
||||
provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvinces(this.AdminContext(), &pb.FindAllRegionProvincesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var provinceMaps = []maps.Map{}
|
||||
for _, province := range provincesResp.RegionProvinces {
|
||||
if province.RegionCountry == nil || len(province.RegionCountry.RouteCode) == 0 {
|
||||
continue
|
||||
}
|
||||
provinceMaps = append(provinceMaps, maps.Map{
|
||||
"id": province.Id,
|
||||
"name": province.Name,
|
||||
"code": "region:province:" + types.String(province.Id),
|
||||
"type": "province",
|
||||
"countryCode": province.RegionCountry.RouteCode,
|
||||
})
|
||||
}
|
||||
this.Data["provinces"] = provinceMaps
|
||||
|
||||
// 搜索引擎
|
||||
agentsResp, err := this.RPC().NSRouteRPC().FindAllAgentNSRoutes(this.AdminContext(), &pb.FindAllAgentNSRoutesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["hasAgentRoutes"] = true
|
||||
for _, route := range agentsResp.NsRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"type": "agent",
|
||||
})
|
||||
}
|
||||
|
||||
this.Data["routes"] = routeMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user