feat: 添加数据库资产、命令拦截器、授权资产等功能,修复GitHub Actions工作流

This commit is contained in:
2026-04-18 07:44:18 +08:00
parent 6e2e2f9387
commit 3c217ab039
64 changed files with 3308 additions and 760 deletions
+40 -21
View File
@@ -32,9 +32,15 @@ func (api AssetGroupApi) GroupsSetEndpoint(c echo.Context) error {
ctx := context.TODO()
repository.AssetGroupRepository.DeleteByParentId(ctx, "")
for i, item := range req {
name := ""
if v, ok := item["name"].(string); ok {
name = v
} else if v, ok := item["title"].(string); ok {
name = v
}
group := model.AssetGroup{
ID: utils.UUID(),
Name: item["name"].(string),
Name: name,
ParentId: "",
Sort: i,
Created: time.Now().UnixMilli(),
@@ -58,9 +64,15 @@ func (api AssetGroupApi) GroupsDeleteEndpoint(c echo.Context) error {
func saveChildren(ctx context.Context, children []interface{}, parentId string) {
for i, item := range children {
m := item.(map[string]interface{})
name := ""
if v, ok := m["name"].(string); ok {
name = v
} else if v, ok := m["title"].(string); ok {
name = v
}
group := model.AssetGroup{
ID: utils.UUID(),
Name: m["name"].(string),
Name: name,
ParentId: parentId,
Sort: i,
Created: time.Now().UnixMilli(),
@@ -109,27 +121,15 @@ func (api AssetGroupApi) TreeEndpoint(c echo.Context) error {
func buildAssetTree(assets []model.Asset, groups []model.AssetGroup, groupId string) []maps.Map {
var nodes []maps.Map
var groupAssets []model.Asset
for _, a := range assets {
groupAssets = append(groupAssets, a)
}
for _, a := range groupAssets {
nodes = append(nodes, maps.Map{
"id": a.ID,
"name": a.Name,
"key": a.ID,
"isLeaf": true,
"protocol": a.Protocol,
"ip": a.IP,
"port": a.Port,
})
}
for _, g := range groups {
if g.ParentId == groupId {
node := maps.Map{
"id": g.ID,
"name": g.Name,
"key": g.ID,
"id": g.ID,
"name": g.Name,
"key": g.ID,
"title": g.Name,
"value": g.ID,
}
children := buildAssetTree(assets, groups, g.ID)
if len(children) > 0 {
@@ -138,6 +138,25 @@ func buildAssetTree(assets []model.Asset, groups []model.AssetGroup, groupId str
nodes = append(nodes, node)
}
}
if groupId == "" {
for _, a := range assets {
nodes = append(nodes, maps.Map{
"id": a.ID,
"name": a.Name,
"key": a.ID,
"title": a.Name,
"value": a.ID,
"isLeaf": true,
"protocol": a.Protocol,
"ip": a.IP,
"port": a.Port,
"extra": maps.Map{
"network": a.IP + ":" + strconv.Itoa(a.Port),
},
})
}
}
return nodes
}
@@ -186,7 +205,7 @@ func (api AssetGroupApi) ChangeGatewayEndpoint(c echo.Context) error {
func (api AssetGroupApi) SortEndpoint(c echo.Context) error {
var req struct {
Id string `json:"id"`
Id string `json:"id"`
BeforeId string `json:"beforeId"`
AfterId string `json:"afterId"`
}