mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-01-08 22:05:48 +08:00
实现路径规则各项数据修改
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package locationutils
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net/http"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type LocationHelper struct {
|
||||
@@ -13,7 +15,8 @@ func NewLocationHelper() *LocationHelper {
|
||||
return &LocationHelper{}
|
||||
}
|
||||
|
||||
func (this *LocationHelper) BeforeAction(action *actions.ActionObject) {
|
||||
func (this *LocationHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
||||
action := actionPtr.Object()
|
||||
if action.Request.Method != http.MethodGet {
|
||||
return
|
||||
}
|
||||
@@ -26,6 +29,21 @@ func (this *LocationHelper) BeforeAction(action *actions.ActionObject) {
|
||||
action.Data["mainTab"] = "setting"
|
||||
action.Data["secondMenuItem"] = "locations"
|
||||
action.Data["tinyLeftMenuItems"] = this.createMenus(serverIdString, locationIdString, action.Data.GetString("tinyMenuItem"))
|
||||
|
||||
// 路径信息
|
||||
parentActionValue := reflect.ValueOf(actionPtr).Elem().FieldByName("ParentAction")
|
||||
if parentActionValue.IsValid() {
|
||||
parentAction, isOk := parentActionValue.Interface().(actionutils.ParentAction)
|
||||
if isOk {
|
||||
locationId := action.ParamInt64("locationId")
|
||||
locationConfig, isOk := FindLocationConfig(&parentAction, locationId)
|
||||
if !isOk {
|
||||
return
|
||||
}
|
||||
action.Data["locationId"] = locationId
|
||||
action.Data["locationConfig"] = locationConfig
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *LocationHelper) createMenus(serverIdString string, locationIdString string, secondMenuItem string) []maps.Map {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package locationutils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
|
||||
// 查找路径规则配置
|
||||
func FindLocationConfig(parentAction *actionutils.ParentAction, locationId int64) (locationConfig *serverconfigs.HTTPLocationConfig, isOk bool) {
|
||||
locationConfigResp, err := parentAction.RPC().HTTPLocationRPC().FindEnabledHTTPLocationConfig(parentAction.AdminContext(), &pb.FindEnabledHTTPLocationConfigRequest{LocationId: locationId})
|
||||
if err != nil {
|
||||
parentAction.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
locationConfig = &serverconfigs.HTTPLocationConfig{}
|
||||
err = json.Unmarshal(locationConfigResp.LocationJSON, locationConfig)
|
||||
if err != nil {
|
||||
parentAction.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = locationConfig.Init()
|
||||
if err != nil {
|
||||
parentAction.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
isOk = true
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user