Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package packages
|
||||
|
||||
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{}) {
|
||||
this.Data["unitOptions"] = []maps.Map{
|
||||
{
|
||||
"code": userconfigs.TrafficPackageSizeUnitGB,
|
||||
"name": "GiB",
|
||||
},
|
||||
{
|
||||
"code": userconfigs.TrafficPackageSizeUnitTB,
|
||||
"name": "TiB",
|
||||
},
|
||||
{
|
||||
"code": userconfigs.TrafficPackageSizeUnitPB,
|
||||
"name": "PiB",
|
||||
},
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Size int32
|
||||
Unit string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var packageId int64
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.TrafficPackage_LogCreateTrafficPackage, packageId)
|
||||
}()
|
||||
|
||||
if params.Size <= 0 {
|
||||
this.FailField("size", "请输入正确的流量包尺寸")
|
||||
return
|
||||
}
|
||||
|
||||
// 限制最大值
|
||||
if params.Unit == userconfigs.TrafficPackageSizeUnitPB && params.Size > 8000 {
|
||||
this.FailField("size", "流量尺寸不能超过8000PB")
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().TrafficPackageRPC().CreateTrafficPackage(this.AdminContext(), &pb.CreateTrafficPackageRequest{
|
||||
Size: params.Size,
|
||||
Unit: params.Unit,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
packageId = createResp.TrafficPackageId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user