mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-02-27 21:25:38 +08:00
优化代码
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
|
||||
@@ -53,7 +54,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_ = httpsConfig.Init(nil)
|
||||
_ = httpsConfig.Init(context.TODO())
|
||||
for _, port := range httpsConfig.AllPorts() {
|
||||
if lists.ContainsInt(httpPorts, port) {
|
||||
conflictingPorts = append(conflictingPorts, port)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package https
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
@@ -43,7 +44,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
httpsConfig.IsOn = true
|
||||
}
|
||||
|
||||
_ = httpsConfig.Init(nil)
|
||||
_ = httpsConfig.Init(context.TODO())
|
||||
var httpsPorts = httpsConfig.AllPorts()
|
||||
|
||||
// 检查http和https端口冲突
|
||||
|
||||
@@ -32,18 +32,18 @@ func (this *RequestCertPopupAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
serverNameConfigs := []*serverconfigs.ServerNameConfig{}
|
||||
var serverNameConfigs = []*serverconfigs.ServerNameConfig{}
|
||||
err = json.Unmarshal(serverNamesResp.ServerNamesJSON, &serverNameConfigs)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
excludeServerNames := []string{}
|
||||
var excludeServerNames = []string{}
|
||||
if len(params.ExcludeServerNames) > 0 {
|
||||
excludeServerNames = strings.Split(params.ExcludeServerNames, ",")
|
||||
}
|
||||
serverNames := []string{}
|
||||
var serverNames = []string{}
|
||||
for _, c := range serverNameConfigs {
|
||||
if len(c.SubNames) == 0 {
|
||||
if domainutils.ValidateDomainFormat(c.Name) && !lists.ContainsString(excludeServerNames, c.Name) {
|
||||
@@ -64,7 +64,12 @@ func (this *RequestCertPopupAction) RunGet(params struct {
|
||||
AdminId: this.AdminId(),
|
||||
UserId: 0,
|
||||
})
|
||||
userMaps := []maps.Map{}
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var userMaps = []maps.Map{}
|
||||
for _, user := range acmeUsersResp.AcmeUsers {
|
||||
description := user.Description
|
||||
if len(description) > 0 {
|
||||
|
||||
@@ -52,6 +52,10 @@ func (this *IndexAction) RunGet(params struct {
|
||||
HttpWebId: webId,
|
||||
HeaderJSON: refJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
isChanged = true
|
||||
}
|
||||
if webConfig.ResponseHeaderPolicy == nil {
|
||||
@@ -75,6 +79,10 @@ func (this *IndexAction) RunGet(params struct {
|
||||
HttpWebId: webId,
|
||||
HeaderJSON: refJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
isChanged = true
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net/http"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type LocationHelper struct {
|
||||
@@ -35,19 +34,19 @@ func (this *LocationHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
||||
|
||||
// 路径信息
|
||||
var currentLocationConfig *serverconfigs.HTTPLocationConfig = nil
|
||||
parentActionValue := reflect.ValueOf(actionPtr).Elem().FieldByName("ParentAction")
|
||||
if parentActionValue.IsValid() {
|
||||
parentAction, isOk := parentActionValue.Interface().(actionutils.ParentAction)
|
||||
if isOk {
|
||||
var locationId = action.ParamInt64("locationId")
|
||||
locationConfig, isOk := FindLocationConfig(&parentAction, locationId)
|
||||
if !isOk {
|
||||
return
|
||||
}
|
||||
action.Data["locationId"] = locationId
|
||||
action.Data["locationConfig"] = locationConfig
|
||||
currentLocationConfig = locationConfig
|
||||
parentActionValue, ok := actionPtr.(interface {
|
||||
Parent() *actionutils.ParentAction
|
||||
})
|
||||
if ok {
|
||||
var parentAction = parentActionValue.Parent()
|
||||
var locationId = action.ParamInt64("locationId")
|
||||
locationConfig, isOk := FindLocationConfig(parentAction, locationId)
|
||||
if !isOk {
|
||||
return
|
||||
}
|
||||
action.Data["locationId"] = locationId
|
||||
action.Data["locationConfig"] = locationConfig
|
||||
currentLocationConfig = locationConfig
|
||||
}
|
||||
|
||||
// 左侧菜单
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package locationutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||
@@ -30,7 +31,7 @@ func FindLocationConfig(parentAction *actionutils.ParentAction, locationId int64
|
||||
return
|
||||
}
|
||||
|
||||
err = locationConfig.Init(nil)
|
||||
err = locationConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
parentAction.ErrorPage(err)
|
||||
return
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package reverseProxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
@@ -64,7 +65,7 @@ func (this *SettingAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
err = reverseProxyConfig.Init(nil)
|
||||
err = reverseProxyConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
@@ -94,6 +94,10 @@ func (this *IndexAction) RunPost(params struct {
|
||||
RequestSameOrigin: websocketConfig.RequestSameOrigin,
|
||||
RequestOrigin: websocketConfig.RequestOrigin,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
websocketRef.WebsocketId = websocketConfig.Id
|
||||
|
||||
@@ -31,7 +31,7 @@ func (this *AddPopupAction) RunGet(params struct {
|
||||
this.Data["reverseProxyId"] = params.ReverseProxyId
|
||||
this.Data["originType"] = params.OriginType
|
||||
|
||||
var serverType = ""
|
||||
var serverType string
|
||||
if params.ServerId > 0 {
|
||||
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{ServerId: params.ServerId})
|
||||
if err != nil {
|
||||
|
||||
@@ -37,7 +37,7 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
||||
this.Data["reverseProxyId"] = params.ReverseProxyId
|
||||
this.Data["originId"] = params.OriginId
|
||||
|
||||
var serverType = ""
|
||||
var serverType string
|
||||
if params.ServerId > 0 {
|
||||
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{
|
||||
ServerId: params.ServerId,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package reverseProxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
@@ -63,7 +64,7 @@ func (this *SettingAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
err = reverseProxyConfig.Init(nil)
|
||||
err = reverseProxyConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
@@ -107,6 +107,10 @@ func (this *IndexAction) RunPost(params struct {
|
||||
RequestSameOrigin: websocketConfig.RequestSameOrigin,
|
||||
RequestOrigin: websocketConfig.RequestOrigin,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
websocketRef.WebsocketId = websocketConfig.Id
|
||||
|
||||
Reference in New Issue
Block a user