1.4.5.2
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/ns/nsutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
DomainId int64
|
||||
UserId int64
|
||||
}) {
|
||||
this.Data["clusterId"] = params.ClusterId
|
||||
this.Data["domainId"] = params.DomainId
|
||||
this.Data["userId"] = params.UserId
|
||||
|
||||
this.Data["rangeTypes"] = dnsconfigs.AllNSRouteRangeTypes()
|
||||
|
||||
// 线路限额
|
||||
maxCustomRoutes, canCreate, err := nsutils.CheckRoutesQuota(this.UserContext(), 1)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["quotaMaxCustomRoutes"] = maxCustomRoutes
|
||||
this.Data["quotaCanCreate"] = canCreate
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
DomainId int64
|
||||
UserId int64
|
||||
|
||||
Name string
|
||||
RangesJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var routeId = int64(0)
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.NSRoute_LogCreateNSRoute, routeId)
|
||||
}()
|
||||
|
||||
// 线路限额
|
||||
maxCustomRoutes, canCreate, err := nsutils.CheckRoutesQuota(this.UserContext(), 1)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if !canCreate {
|
||||
this.Fail("超出线路最大限额(" + types.String(maxCustomRoutes) + "个),请升级套餐后再试")
|
||||
return
|
||||
}
|
||||
|
||||
params.Must.Field("name", params.Name).
|
||||
Require("请输入线路名称")
|
||||
|
||||
ranges, err := dnsconfigs.InitNSRangesFromJSON(params.RangesJSON)
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
if len(ranges) == 0 {
|
||||
this.Fail("请添加线路范围")
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().NSRouteRPC().CreateNSRoute(this.UserContext(), &pb.CreateNSRouteRequest{
|
||||
NsClusterId: params.ClusterId,
|
||||
NsDomainId: params.DomainId,
|
||||
UserId: params.UserId,
|
||||
Name: params.Name,
|
||||
RangesJSON: params.RangesJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
routeId = createResp.NsRouteId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user