mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
IP名单中可以批量删除最多10000个IP
This commit is contained in:
82
internal/web/actions/default/servers/iplists/deleteCount.go
Normal file
82
internal/web/actions/default/servers/iplists/deleteCount.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package iplists
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DeleteCountAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteCountAction) RunPost(params struct {
|
||||
Ip string
|
||||
Keyword string
|
||||
GlobalOnly bool
|
||||
Unread bool
|
||||
EventLevel string
|
||||
ListType string
|
||||
|
||||
Count int64
|
||||
}) {
|
||||
|
||||
var count = params.Count
|
||||
if count <= 0 || count >= 100_000 {
|
||||
this.Fail("'count' 参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
itemIdsResp, err := this.RPC().IPItemRPC().ListAllIPItemIds(this.AdminContext(), &pb.ListAllIPItemIdsRequest{
|
||||
Keyword: params.Keyword,
|
||||
GlobalOnly: params.GlobalOnly,
|
||||
Unread: params.Unread,
|
||||
EventLevel: params.EventLevel,
|
||||
ListType: params.ListType,
|
||||
Ip: params.Ip,
|
||||
Offset: 0,
|
||||
Size: count,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var itemIds = itemIdsResp.IpItemIds
|
||||
|
||||
if len(itemIds) == 0 {
|
||||
this.Success()
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
defer func() {
|
||||
var itemIdStrings = []string{}
|
||||
for _, itemId := range itemIds {
|
||||
itemIdStrings = append(itemIdStrings, types.String(itemId))
|
||||
}
|
||||
|
||||
var itemIdsDescription = ""
|
||||
if len(itemIdStrings) > 10 {
|
||||
itemIdsDescription = strings.Join(itemIdStrings[:10], ", ") + " ..."
|
||||
} else {
|
||||
itemIdsDescription = strings.Join(itemIdStrings, ", ")
|
||||
}
|
||||
this.CreateLogInfo(codes.IPList_LogDeleteIPBatch, itemIdsDescription)
|
||||
}()
|
||||
|
||||
_, err = this.RPC().IPItemRPC().DeleteIPItems(this.AdminContext(), &pb.DeleteIPItemsRequest{IpItemIds: itemIds})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 通知左侧菜单Badge更新
|
||||
helpers.NotifyIPItemsCountChanges()
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -63,6 +63,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["totalItems"] = count
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
itemsResp, err := this.RPC().IPItemRPC().ListAllEnabledIPItems(this.AdminContext(), &pb.ListAllEnabledIPItemsRequest{
|
||||
|
||||
@@ -22,6 +22,7 @@ func init() {
|
||||
Get("/exportData", new(ExportDataAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
Post("/deleteItems", new(DeleteItemsAction)).
|
||||
Post("/deleteCount", new(DeleteCountAction)).
|
||||
GetPost("/test", new(TestAction)).
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
Get("/items", new(ItemsAction)).
|
||||
|
||||
Reference in New Issue
Block a user