1.4.5.2
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package instances
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
UserInstanceId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserADInstance_LogDeleteUserADInstance, params.UserInstanceId)
|
||||
|
||||
_, err := this.RPC().UserADInstanceRPC().DeleteUserADInstance(this.UserContext(), &pb.DeleteUserADInstanceRequest{UserADInstanceId: params.UserInstanceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package instances
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/utils/dateutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
NetworkId int64
|
||||
PeriodId int64
|
||||
}) {
|
||||
countResp, err := this.RPC().UserADInstanceRPC().CountUserADInstances(this.UserContext(), &pb.CountUserADInstancesRequest{
|
||||
AdNetworkId: params.NetworkId,
|
||||
ExpiresDay: "",
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
userInstancesResp, err := this.RPC().UserADInstanceRPC().ListUserADInstances(this.UserContext(), &pb.ListUserADInstancesRequest{
|
||||
AdNetworkId: params.NetworkId,
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
ExpiresDay: "",
|
||||
AvailableOnly: false,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var userInstanceMaps = []maps.Map{}
|
||||
for _, userInstance := range userInstancesResp.UserADInstances {
|
||||
// 实例
|
||||
var instanceMap = maps.Map{
|
||||
"id": 0,
|
||||
"userInstanceId": 0,
|
||||
}
|
||||
if userInstance.AdPackageInstance != nil {
|
||||
instanceMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.Id,
|
||||
"userInstanceId": userInstance.AdPackageInstance.UserInstanceId,
|
||||
}
|
||||
}
|
||||
|
||||
// 产品
|
||||
var packageMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.AdPackageInstance != nil && userInstance.AdPackageInstance.AdPackage != nil {
|
||||
packageMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.AdPackage.Id,
|
||||
"summary": userInstance.AdPackageInstance.AdPackage.Summary,
|
||||
}
|
||||
}
|
||||
|
||||
// 实例
|
||||
var ipAddresses = []string{}
|
||||
if userInstance.AdPackageInstance != nil && len(userInstance.AdPackageInstance.IpAddresses) > 0 {
|
||||
ipAddresses = userInstance.AdPackageInstance.IpAddresses
|
||||
}
|
||||
|
||||
userInstanceMaps = append(userInstanceMaps, maps.Map{
|
||||
"id": userInstance.Id,
|
||||
"dayFrom": dateutils.SplitYmd(userInstance.DayFrom),
|
||||
"dayTo": dateutils.SplitYmd(userInstance.DayTo),
|
||||
"instance": instanceMap,
|
||||
"package": packageMap,
|
||||
"ipAddresses": ipAddresses,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", userInstance.CreatedAt),
|
||||
"periodCount": userInstance.AdPackagePeriodCount,
|
||||
"periodUnitName": userconfigs.ADPackagePeriodUnitName(userInstance.AdPackagePeriodUnit),
|
||||
"canDelete": true,
|
||||
"isExpired": userInstance.DayTo < timeutil.Format("Ymd"),
|
||||
"isAvailable": userInstance.IsAvailable,
|
||||
"countObjects": userInstance.CountObjects,
|
||||
})
|
||||
}
|
||||
this.Data["userInstances"] = userInstanceMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package instances
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/utils/dateutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type RenewAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *RenewAction) RunGet(params struct {
|
||||
UserInstanceId int64
|
||||
}) {
|
||||
userInstanceResp, err := this.RPC().UserADInstanceRPC().FindUserADInstance(this.UserContext(), &pb.FindUserADInstanceRequest{UserADInstanceId: params.UserInstanceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var userInstance = userInstanceResp.UserADInstance
|
||||
if userInstance == nil {
|
||||
this.NotFound("userInstance", params.UserInstanceId)
|
||||
return
|
||||
}
|
||||
|
||||
// 实例
|
||||
var instanceMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.AdPackageInstance != nil {
|
||||
if userInstance.AdPackageInstance.IpAddresses == nil {
|
||||
userInstance.AdPackageInstance.IpAddresses = []string{}
|
||||
}
|
||||
instanceMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.Id,
|
||||
"ipAddresses": userInstance.AdPackageInstance.IpAddresses,
|
||||
}
|
||||
}
|
||||
|
||||
// 产品
|
||||
var packageMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
var packageId int64
|
||||
if userInstance.AdPackageInstance != nil && userInstance.AdPackageInstance.AdPackage != nil {
|
||||
packageId = userInstance.AdPackageInstance.AdPackage.Id
|
||||
packageMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.AdPackage.Id,
|
||||
"summary": userInstance.AdPackageInstance.AdPackage.Summary,
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["userInstance"] = maps.Map{
|
||||
"id": userInstance.Id,
|
||||
"periodId": userInstance.AdPackagePeriodId,
|
||||
"dayTo": dateutils.SplitYmd(userInstance.DayTo),
|
||||
"today": timeutil.Format("Y-m-d"),
|
||||
"isExpired": len(userInstance.DayTo) == 0 || userInstance.DayTo < timeutil.Format("Ymd"),
|
||||
"isAvailable": userInstance.IsAvailable,
|
||||
"instance": instanceMap,
|
||||
"package": packageMap,
|
||||
}
|
||||
|
||||
// 价格选项
|
||||
if packageId > 0 {
|
||||
pricesResp, err := this.RPC().ADPackagePriceRPC().FindADPackagePrices(this.UserContext(), &pb.FindADPackagePricesRequest{AdPackageId: packageId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var priceMaps = []maps.Map{}
|
||||
var allValidPeriodIds = []int64{}
|
||||
for _, price := range pricesResp.AdPackagePrices {
|
||||
allValidPeriodIds = append(allValidPeriodIds, price.AdPackagePeriodId)
|
||||
priceMaps = append(priceMaps, maps.Map{
|
||||
"periodId": price.AdPackagePeriodId,
|
||||
"price": price.Price,
|
||||
})
|
||||
}
|
||||
this.Data["prices"] = priceMaps
|
||||
|
||||
// 有效期选项
|
||||
var periodMaps = []maps.Map{}
|
||||
periodResp, err := this.RPC().ADPackagePeriodRPC().FindAllAvailableADPackagePeriods(this.UserContext(), &pb.FindAllAvailableADPackagePeriodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, period := range periodResp.AdPackagePeriods {
|
||||
if !lists.ContainsInt64(allValidPeriodIds, period.Id) {
|
||||
continue
|
||||
}
|
||||
periodMaps = append(periodMaps, maps.Map{
|
||||
"id": period.Id,
|
||||
"count": period.Count,
|
||||
"unit": period.Unit,
|
||||
"unitName": userconfigs.ADPackagePeriodUnitName(period.Unit),
|
||||
})
|
||||
}
|
||||
this.Data["allPeriods"] = periodMaps
|
||||
} else {
|
||||
this.Data["allPeriods"] = []maps.Map{}
|
||||
this.Data["prices"] = []maps.Map{}
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package instances
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/utils/dateutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/finance/financeutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type RenewConfirmAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *RenewConfirmAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *RenewConfirmAction) RunGet(params struct {
|
||||
UserInstanceId int64
|
||||
PeriodId int64
|
||||
}) {
|
||||
this.Data["userInstanceId"] = params.UserInstanceId
|
||||
this.Data["periodId"] = params.PeriodId
|
||||
|
||||
periodResp, err := this.RPC().ADPackagePeriodRPC().FindADPackagePeriod(this.UserContext(), &pb.FindADPackagePeriodRequest{AdPackagePeriodId: params.PeriodId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var period = periodResp.AdPackagePeriod
|
||||
if period == nil {
|
||||
this.ErrorText("period not found")
|
||||
return
|
||||
}
|
||||
this.Data["periodName"] = types.String(period.Count) + userconfigs.ADPackagePeriodUnitName(period.Unit)
|
||||
|
||||
userInstanceResp, err := this.RPC().UserADInstanceRPC().FindUserADInstance(this.UserContext(), &pb.FindUserADInstanceRequest{UserADInstanceId: params.UserInstanceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var userInstance = userInstanceResp.UserADInstance
|
||||
if userInstance == nil {
|
||||
this.NotFound("userInstance", params.UserInstanceId)
|
||||
return
|
||||
}
|
||||
this.Data["dayTo"] = dateutils.SplitYmd(userInstance.DayTo)
|
||||
|
||||
// 实例
|
||||
if userInstance.AdPackageInstance == nil {
|
||||
this.ErrorText("adPackageInstance not found")
|
||||
return
|
||||
}
|
||||
if userInstance.AdPackageInstance.IpAddresses == nil {
|
||||
userInstance.AdPackageInstance.IpAddresses = []string{}
|
||||
}
|
||||
this.Data["ipAddresses"] = userInstance.AdPackageInstance.IpAddresses
|
||||
|
||||
// 产品
|
||||
if userInstance.AdPackageInstance.AdPackage == nil {
|
||||
this.ErrorText("adPackage not found")
|
||||
return
|
||||
}
|
||||
var packageId = userInstance.AdPackageInstance.AdPackage.Id
|
||||
this.Data["packageSummary"] = userInstance.AdPackageInstance.AdPackage.Summary
|
||||
|
||||
// 价格
|
||||
priceResp, err := this.RPC().ADPackagePriceRPC().FindADPackagePrice(this.UserContext(), &pb.FindADPackagePriceRequest{
|
||||
AdPackageId: packageId,
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
Count: 1,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["amount"] = priceResp.Amount
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *RenewConfirmAction) RunPost(params struct {
|
||||
UserInstanceId int64
|
||||
PeriodId int64
|
||||
|
||||
MethodCode string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
if params.UserInstanceId <= 0 || params.PeriodId <= 0 {
|
||||
this.Fail("参数错误,请重新下单")
|
||||
return
|
||||
}
|
||||
|
||||
userInstanceResp, err := this.RPC().UserADInstanceRPC().FindUserADInstance(this.UserContext(), &pb.FindUserADInstanceRequest{UserADInstanceId: params.UserInstanceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var userInstance = userInstanceResp.UserADInstance
|
||||
if userInstance == nil {
|
||||
this.NotFound("userInstance", params.UserInstanceId)
|
||||
return
|
||||
}
|
||||
|
||||
if userInstance.AdPackageInstance == nil {
|
||||
this.ErrorText("invalid adPackageInstance")
|
||||
return
|
||||
}
|
||||
var packageId = userInstance.AdPackageInstance.AdPackageId
|
||||
if !userInstance.IsAvailable {
|
||||
this.ErrorText("invalid user instance")
|
||||
return
|
||||
}
|
||||
|
||||
periodResp, err := this.RPC().ADPackagePeriodRPC().FindADPackagePeriod(this.UserContext(), &pb.FindADPackagePeriodRequest{AdPackagePeriodId: params.PeriodId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var period = periodResp.AdPackagePeriod
|
||||
if period == nil {
|
||||
this.Fail("invalid 'periodId'")
|
||||
return
|
||||
}
|
||||
|
||||
priceResp, err := this.RPC().ADPackagePriceRPC().FindADPackagePrice(this.UserContext(), &pb.FindADPackagePriceRequest{
|
||||
AdPackageId: packageId,
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
Count: 1,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var amount = priceResp.Amount
|
||||
if amount <= 0 {
|
||||
this.Fail("invalid 'amount': " + types.String(amount))
|
||||
return
|
||||
}
|
||||
|
||||
// 使用余额购买
|
||||
this.Data["success"] = false
|
||||
this.Data["orderCode"] = ""
|
||||
if params.MethodCode == "@balance" {
|
||||
balance, err := financeutils.FindUserBalance(this.UserContext())
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if amount > balance {
|
||||
this.Fail("当前余额不足,需要:" + fmt.Sprintf("%.2f元", amount) + ",现有:" + fmt.Sprintf("%.2f元", balance) + " ,请充值后再试")
|
||||
return
|
||||
}
|
||||
|
||||
// 直接购买
|
||||
_, err = this.RPC().UserADInstanceRPC().RenewUserADInstance(this.UserContext(), &pb.RenewUserADInstanceRequest{
|
||||
UserADInstanceId: params.UserInstanceId,
|
||||
AdPackagePeriodId: params.PeriodId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["success"] = true
|
||||
this.Success()
|
||||
return
|
||||
}
|
||||
|
||||
// 生成订单
|
||||
var orderParams = &userconfigs.OrderTypeRenewAntiDDoSInstanceParams{
|
||||
UserInstanceId: params.UserInstanceId,
|
||||
PeriodId: params.PeriodId,
|
||||
}
|
||||
orderParamsJSON, err := json.Marshal(orderParams)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := this.RPC().UserOrderRPC().CreateUserOrder(this.UserContext(), &pb.CreateUserOrderRequest{
|
||||
Type: userconfigs.OrderTypeRenewAntiDDoSInstance,
|
||||
OrderMethodCode: params.MethodCode,
|
||||
Amount: amount,
|
||||
ParamsJSON: orderParamsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["orderCode"] = resp.Code
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package instances
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/utils/dateutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type UpdateObjectsPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateObjectsPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdateObjectsPopupAction) RunGet(params struct {
|
||||
UserInstanceId int64
|
||||
}) {
|
||||
userInstanceResp, err := this.RPC().UserADInstanceRPC().FindUserADInstance(this.UserContext(), &pb.FindUserADInstanceRequest{UserADInstanceId: params.UserInstanceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var userInstance = userInstanceResp.UserADInstance
|
||||
if userInstance == nil {
|
||||
this.NotFound("userInstance", params.UserInstanceId)
|
||||
return
|
||||
}
|
||||
var objectMaps = []maps.Map{}
|
||||
if len(userInstance.ObjectsJSON) > 0 {
|
||||
err = json.Unmarshal(userInstance.ObjectsJSON, &objectMaps)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 用户
|
||||
var userMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": userInstance.User.Id,
|
||||
"fullname": userInstance.User.Fullname,
|
||||
"username": userInstance.User.Username,
|
||||
}
|
||||
}
|
||||
|
||||
// 实例
|
||||
var instanceMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.AdPackageInstance != nil {
|
||||
if userInstance.AdPackageInstance.IpAddresses == nil {
|
||||
userInstance.AdPackageInstance.IpAddresses = []string{}
|
||||
}
|
||||
instanceMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.Id,
|
||||
"ipAddresses": userInstance.AdPackageInstance.IpAddresses,
|
||||
}
|
||||
}
|
||||
|
||||
// 产品
|
||||
var packageMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if userInstance.AdPackageInstance != nil && userInstance.AdPackageInstance.AdPackage != nil {
|
||||
packageMap = maps.Map{
|
||||
"id": userInstance.AdPackageInstance.AdPackage.Id,
|
||||
"summary": userInstance.AdPackageInstance.AdPackage.Summary,
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["userInstance"] = maps.Map{
|
||||
"id": userInstance.Id,
|
||||
"periodId": userInstance.AdPackagePeriodId,
|
||||
"isAvailable": userInstance.IsAvailable,
|
||||
"objects": objectMaps,
|
||||
"dayTo": dateutils.SplitYmd(userInstance.DayTo),
|
||||
"today": timeutil.Format("Y-m-d"),
|
||||
"isExpired": len(userInstance.DayTo) == 0 || userInstance.DayTo < timeutil.Format("Ymd"),
|
||||
"user": userMap,
|
||||
"instance": instanceMap,
|
||||
"package": packageMap,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateObjectsPopupAction) RunPost(params struct {
|
||||
UserInstanceId int64
|
||||
ObjectCodesJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserADInstance_LogUpdateUserADInstanceObjects, params.UserInstanceId)
|
||||
|
||||
var objectCodes = []string{}
|
||||
if len(params.ObjectCodesJSON) > 0 {
|
||||
err := json.Unmarshal(params.ObjectCodesJSON, &objectCodes)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 检查有没有超出最大防护对象数量
|
||||
|
||||
_, err := this.RPC().UserADInstanceRPC().UpdateUserADInstanceObjects(this.UserContext(), &pb.UpdateUserADInstanceObjectsRequest{
|
||||
UserADInstanceId: params.UserInstanceId,
|
||||
ObjectCodes: objectCodes,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package instances
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UserServersAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UserServersAction) RunPost(params struct {
|
||||
Page int32
|
||||
}) {
|
||||
var size int64 = 10
|
||||
|
||||
// 数量
|
||||
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersMatch(this.UserContext(), &pb.CountAllEnabledServersMatchRequest{
|
||||
UserId: this.UserId(),
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count, size)
|
||||
|
||||
// 列表
|
||||
serversResp, err := this.RPC().ServerRPC().ListEnabledServersMatch(this.UserContext(), &pb.ListEnabledServersMatchRequest{
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
UserId: this.UserId(),
|
||||
IgnoreServerNames: true,
|
||||
IgnoreSSLCerts: true,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var serverMaps = []maps.Map{}
|
||||
for _, server := range serversResp.Servers {
|
||||
serverMaps = append(serverMaps, maps.Map{
|
||||
"id": server.Id,
|
||||
"name": server.Name,
|
||||
})
|
||||
}
|
||||
this.Data["servers"] = serverMaps
|
||||
this.Data["page"] = maps.Map{
|
||||
"max": page.Max,
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user