// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . package clusters import ( "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils" "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/maps" ) type InternalAction struct { actionutils.ParentAction } func (this *InternalAction) Init() { this.Nav("", "", "internal") } func (this *InternalAction) RunGet(params struct{}) { this.Data["ispRoutes"] = dnsconfigs.AllDefaultISPRoutes this.Data["chinaProvinceRoutes"] = dnsconfigs.AllDefaultChinaProvinceRoutes this.Data["worldRegionRoutes"] = dnsconfigs.AllDefaultWorldRegionRoutes // Agent相关线路 agentsResp, err := this.RPC().NSRouteRPC().FindAllAgentNSRoutes(this.UserContext(), &pb.FindAllAgentNSRoutesRequest{}) if err != nil { this.ErrorPage(err) return } var agentRouteMaps = []maps.Map{} for _, route := range agentsResp.NsRoutes { agentRouteMaps = append(agentRouteMaps, maps.Map{ "name": route.Name, "code": route.Code, }) } this.Data["agentRoutes"] = agentRouteMaps // 系统内置公用线路 publicRoutesResp, err := this.RPC().NSRouteRPC().FindAllPublicNSRoutes(this.UserContext(), &pb.FindAllPublicRoutesRequest{}) if err != nil { this.ErrorPage(err) return } var publicCategoryMaps = []maps.Map{} var publicCategoryIds = []int64{} var publicRouteMaps = []maps.Map{} for _, route := range publicRoutesResp.NsRoutes { var categoryId int64 = 0 if route.NsRouteCategory != nil { categoryId = route.NsRouteCategory.Id } publicRouteMaps = append(publicRouteMaps, maps.Map{ "id": route.Id, "name": route.Name, "code": route.Code, "categoryId": categoryId, }) // 未分类 if route.NsRouteCategory == nil { if !lists.ContainsInt64(publicCategoryIds, 0) { publicCategoryIds = append(publicCategoryIds, 0) publicCategoryMaps = append(publicCategoryMaps, maps.Map{ "id": 0, "name": "官方线路", }) } continue } // 有分类 if !lists.ContainsInt64(publicCategoryIds, route.NsRouteCategory.Id) { publicCategoryIds = append(publicCategoryIds, route.NsRouteCategory.Id) publicCategoryMaps = append(publicCategoryMaps, maps.Map{ "id": route.NsRouteCategory.Id, "name": route.NsRouteCategory.Name, }) } } this.Data["publicCategories"] = publicCategoryMaps this.Data["publicRoutes"] = publicRouteMaps this.Show() }