Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package antiddos
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
NetworkId int64
|
||||
}) {
|
||||
this.Data["networkId"] = params.NetworkId
|
||||
|
||||
countResp, err := this.RPC().ADPackageRPC().CountADPackages(this.AdminContext(), &pb.CountADPackagesRequest{
|
||||
AdNetworkId: params.NetworkId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
packagesResp, err := this.RPC().ADPackageRPC().ListADPackages(this.AdminContext(), &pb.ListADPackagesRequest{
|
||||
AdNetworkId: params.NetworkId,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var packageMaps = []maps.Map{}
|
||||
for _, p := range packagesResp.AdPackages {
|
||||
// 线路
|
||||
var networkMap = maps.Map{
|
||||
"id": 0,
|
||||
"name": "",
|
||||
"isOn": false,
|
||||
}
|
||||
if p.AdNetwork != nil {
|
||||
networkMap = maps.Map{
|
||||
"id": p.AdNetwork.Id,
|
||||
"name": p.AdNetwork.Name,
|
||||
"isOn": p.AdNetwork.IsOn,
|
||||
}
|
||||
}
|
||||
|
||||
// 价格项数量
|
||||
countPricesResp, err := this.RPC().ADPackagePriceRPC().CountADPackagePrices(this.AdminContext(), &pb.CountADPackagePricesRequest{AdPackageId: p.Id})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countPrices = countPricesResp.Count
|
||||
|
||||
// 实例数量
|
||||
countInstancesResp, err := this.RPC().ADPackageInstanceRPC().CountADPackageInstances(this.AdminContext(), &pb.CountADPackageInstancesRequest{AdPackageId: p.Id})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countInstances = countInstancesResp.Count
|
||||
|
||||
packageMaps = append(packageMaps, maps.Map{
|
||||
"id": p.Id,
|
||||
"isOn": p.IsOn,
|
||||
"protectionBandwidthSize": p.ProtectionBandwidthSize,
|
||||
"protectionBandwidthUnit": p.ProtectionBandwidthUnit,
|
||||
"serverBandwidthSize": p.ServerBandwidthSize,
|
||||
"serverBandwidthUnit": p.ServerBandwidthUnit,
|
||||
"network": networkMap,
|
||||
"countPrices": countPrices,
|
||||
"countInstances": countInstances,
|
||||
})
|
||||
}
|
||||
this.Data["packages"] = packageMaps
|
||||
|
||||
// 所有线路
|
||||
networkResp, err := this.RPC().ADNetworkRPC().FindAllADNetworks(this.AdminContext(), &pb.FindAllADNetworkRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var networkMaps = []maps.Map{}
|
||||
for _, network := range networkResp.AdNetworks {
|
||||
networkMaps = append(networkMaps, maps.Map{
|
||||
"id": network.Id,
|
||||
"name": network.Name,
|
||||
"isOn": network.IsOn,
|
||||
})
|
||||
}
|
||||
this.Data["networks"] = networkMaps
|
||||
|
||||
// 价格项总数量
|
||||
periodsResp, err := this.RPC().ADPackagePeriodRPC().FindAllAvailableADPackagePeriods(this.AdminContext(), &pb.FindAllAvailableADPackagePeriodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["totalPriceItems"] = len(periodsResp.AdPackagePeriods)
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user