// 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/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/userconfigs" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" ) type CreatePopupAction struct { actionutils.ParentAction } func (this *CreatePopupAction) Init() { this.Nav("", "", "") } func (this *CreatePopupAction) RunGet(params struct{}) { // 线路选项 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 // 带宽单位 this.Data["protectionUnitOptions"] = []maps.Map{ { "code": userconfigs.ADPackageSizeUnitGb, "name": "Gbps", }, { "code": userconfigs.ADPackageSizeUnitTb, "name": "Tbps", }, } this.Data["serverUnitOptions"] = []maps.Map{ { "code": userconfigs.ADPackageSizeUnitMb, "name": "Mbps", }, { "code": userconfigs.ADPackageSizeUnitGb, "name": "Gbps", }, { "code": userconfigs.ADPackageSizeUnitTb, "name": "Tbps", }, } this.Show() } func (this *CreatePopupAction) RunPost(params struct { NetworkId int64 ProtectionBandwidthSize int32 ProtectionBandwidthUnit string ServerBandwidthSize int32 ServerBandwidthUnit string Must *actions.Must CSRF *actionutils.CSRF }) { var packageId int64 defer func() { this.CreateLogInfo(codes.ADPackage_LogCreateADPackage, packageId) }() if params.NetworkId <= 0 { this.Fail("请选择所属线路") return } if params.ProtectionBandwidthSize <= 0 || len(params.ProtectionBandwidthUnit) == 0 { this.FailField("protectionBandwidthSize", "请输入防护带宽") return } if params.ServerBandwidthSize <= 0 || len(params.ServerBandwidthUnit) == 0 { this.FailField("serverBandwidthSize", "请输入业务带宽") return } createResp, err := this.RPC().ADPackageRPC().CreateADPackage(this.AdminContext(), &pb.CreateADPackageRequest{ AdNetworkId: params.NetworkId, ProtectionBandwidthSize: params.ProtectionBandwidthSize, ProtectionBandwidthUnit: params.ProtectionBandwidthUnit, ServerBandwidthSize: params.ServerBandwidthSize, ServerBandwidthUnit: params.ServerBandwidthUnit, }) if err != nil { this.ErrorPage(err) return } packageId = createResp.AdPackageId this.Success() }