feat: 添加数据库资产、命令拦截器、授权资产等功能,修复GitHub Actions工作流
This commit is contained in:
+150
-43
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"next-terminal/server/common"
|
||||
"next-terminal/server/common/maps"
|
||||
"next-terminal/server/dto"
|
||||
"next-terminal/server/model"
|
||||
@@ -68,27 +69,27 @@ func (api WebsiteApi) CreateEndpoint(c echo.Context) error {
|
||||
}
|
||||
|
||||
item := &model.Website{
|
||||
ID: utils.UUID(),
|
||||
Name: req.Name,
|
||||
Enabled: req.Enabled,
|
||||
TargetUrl: req.TargetUrl,
|
||||
TargetHost: req.TargetHost,
|
||||
TargetPort: req.TargetPort,
|
||||
Domain: req.Domain,
|
||||
AsciiDomain: req.AsciiDomain,
|
||||
Entrance: req.Entrance,
|
||||
Description: req.Description,
|
||||
Status: req.Status,
|
||||
StatusText: req.StatusText,
|
||||
GatewayType: req.GatewayType,
|
||||
GatewayId: req.GatewayId,
|
||||
BasicAuth: serializeJSON(req.BasicAuth),
|
||||
Headers: serializeJSON(req.Headers),
|
||||
Cert: serializeJSON(req.Cert),
|
||||
Public: serializeJSON(req.Public),
|
||||
TempAllow: serializeJSON(req.TempAllow),
|
||||
GroupId: req.GroupId,
|
||||
Sort: req.Sort,
|
||||
ID: utils.UUID(),
|
||||
Name: req.Name,
|
||||
Enabled: req.Enabled,
|
||||
TargetUrl: req.TargetUrl,
|
||||
TargetHost: req.TargetHost,
|
||||
TargetPort: req.TargetPort,
|
||||
Domain: req.Domain,
|
||||
AsciiDomain: req.AsciiDomain,
|
||||
Entrance: req.Entrance,
|
||||
Description: req.Description,
|
||||
Status: req.Status,
|
||||
StatusText: req.StatusText,
|
||||
GatewayType: req.GatewayType,
|
||||
GatewayId: req.GatewayId,
|
||||
BasicAuth: serializeJSON(req.BasicAuth),
|
||||
Headers: serializeJSON(req.Headers),
|
||||
Cert: serializeJSON(req.Cert),
|
||||
Public: serializeJSON(req.Public),
|
||||
TempAllow: serializeJSON(req.TempAllow),
|
||||
GroupId: req.GroupId,
|
||||
Sort: req.Sort,
|
||||
}
|
||||
|
||||
if err := repository.WebsiteRepository.Create(context.TODO(), item); err != nil {
|
||||
@@ -105,27 +106,27 @@ func (api WebsiteApi) UpdateEndpoint(c echo.Context) error {
|
||||
}
|
||||
|
||||
item := &model.Website{
|
||||
ID: id,
|
||||
Name: req.Name,
|
||||
Enabled: req.Enabled,
|
||||
TargetUrl: req.TargetUrl,
|
||||
TargetHost: req.TargetHost,
|
||||
TargetPort: req.TargetPort,
|
||||
Domain: req.Domain,
|
||||
AsciiDomain: req.AsciiDomain,
|
||||
Entrance: req.Entrance,
|
||||
Description: req.Description,
|
||||
Status: req.Status,
|
||||
StatusText: req.StatusText,
|
||||
GatewayType: req.GatewayType,
|
||||
GatewayId: req.GatewayId,
|
||||
BasicAuth: serializeJSON(req.BasicAuth),
|
||||
Headers: serializeJSON(req.Headers),
|
||||
Cert: serializeJSON(req.Cert),
|
||||
Public: serializeJSON(req.Public),
|
||||
TempAllow: serializeJSON(req.TempAllow),
|
||||
GroupId: req.GroupId,
|
||||
Sort: req.Sort,
|
||||
ID: id,
|
||||
Name: req.Name,
|
||||
Enabled: req.Enabled,
|
||||
TargetUrl: req.TargetUrl,
|
||||
TargetHost: req.TargetHost,
|
||||
TargetPort: req.TargetPort,
|
||||
Domain: req.Domain,
|
||||
AsciiDomain: req.AsciiDomain,
|
||||
Entrance: req.Entrance,
|
||||
Description: req.Description,
|
||||
Status: req.Status,
|
||||
StatusText: req.StatusText,
|
||||
GatewayType: req.GatewayType,
|
||||
GatewayId: req.GatewayId,
|
||||
BasicAuth: serializeJSON(req.BasicAuth),
|
||||
Headers: serializeJSON(req.Headers),
|
||||
Cert: serializeJSON(req.Cert),
|
||||
Public: serializeJSON(req.Public),
|
||||
TempAllow: serializeJSON(req.TempAllow),
|
||||
GroupId: req.GroupId,
|
||||
Sort: req.Sort,
|
||||
}
|
||||
|
||||
if err := repository.WebsiteRepository.UpdateById(context.TODO(), item, id); err != nil {
|
||||
@@ -152,18 +153,124 @@ func (api WebsiteApi) GetEndpoint(c echo.Context) error {
|
||||
}
|
||||
|
||||
func (api WebsiteApi) GroupsGetEndpoint(c echo.Context) error {
|
||||
return Success(c, []interface{}{})
|
||||
groups, err := repository.WebsiteGroupRepository.FindAll(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tree := buildWebsiteGroupTree(groups, "")
|
||||
return Success(c, tree)
|
||||
}
|
||||
|
||||
func buildWebsiteGroupTree(groups []model.WebsiteGroup, parentId string) []maps.Map {
|
||||
var tree []maps.Map
|
||||
for _, g := range groups {
|
||||
if g.ParentId == parentId {
|
||||
node := maps.Map{
|
||||
"id": g.ID,
|
||||
"name": g.Name,
|
||||
"title": g.Name,
|
||||
"key": g.ID,
|
||||
"value": g.ID,
|
||||
}
|
||||
children := buildWebsiteGroupTree(groups, g.ID)
|
||||
if len(children) > 0 {
|
||||
node["children"] = children
|
||||
}
|
||||
tree = append(tree, node)
|
||||
}
|
||||
}
|
||||
return tree
|
||||
}
|
||||
|
||||
func (api WebsiteApi) GroupsSetEndpoint(c echo.Context) error {
|
||||
var req []map[string]interface{}
|
||||
if err := c.Bind(&req); err != nil {
|
||||
return err
|
||||
}
|
||||
ctx := context.TODO()
|
||||
repository.WebsiteGroupRepository.DeleteAll(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.WebsiteGroup{
|
||||
ID: utils.UUID(),
|
||||
Name: name,
|
||||
ParentId: "",
|
||||
Sort: i,
|
||||
Created: common.NowJsonTime(),
|
||||
}
|
||||
repository.WebsiteGroupRepository.Create(ctx, &group)
|
||||
if subChildren, ok := item["children"].([]interface{}); ok {
|
||||
saveWebsiteGroupChildren(ctx, subChildren, group.ID)
|
||||
}
|
||||
}
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
func saveWebsiteGroupChildren(ctx context.Context, children []interface{}, parentId string) {
|
||||
for i, child := range children {
|
||||
m, ok := child.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
name := ""
|
||||
if v, ok := m["name"].(string); ok {
|
||||
name = v
|
||||
} else if v, ok := m["title"].(string); ok {
|
||||
name = v
|
||||
}
|
||||
group := model.WebsiteGroup{
|
||||
ID: utils.UUID(),
|
||||
Name: name,
|
||||
ParentId: parentId,
|
||||
Sort: i,
|
||||
Created: common.NowJsonTime(),
|
||||
}
|
||||
repository.WebsiteGroupRepository.Create(ctx, &group)
|
||||
if subChildren, ok := m["children"].([]interface{}); ok {
|
||||
saveWebsiteGroupChildren(ctx, subChildren, group.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (api WebsiteApi) GroupsDeleteEndpoint(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
|
||||
count, err := repository.WebsiteGroupRepository.CountByParentId(context.TODO(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return Fail(c, -1, "该分组下存在子分组,无法删除")
|
||||
}
|
||||
|
||||
if err := repository.WebsiteGroupRepository.DeleteById(context.TODO(), id); err != nil {
|
||||
return err
|
||||
}
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
func (api WebsiteApi) ChangeGroupEndpoint(c echo.Context) error {
|
||||
var req struct {
|
||||
WebsiteIds []string `json:"websiteIds"`
|
||||
GroupId string `json:"groupId"`
|
||||
}
|
||||
if err := c.Bind(&req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, websiteId := range req.WebsiteIds {
|
||||
website, err := repository.WebsiteRepository.FindById(context.TODO(), websiteId)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
website.GroupId = req.GroupId
|
||||
repository.WebsiteRepository.UpdateById(context.TODO(), &website, websiteId)
|
||||
}
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user