优化添加端口、添加源站相关交互

This commit is contained in:
刘祥超
2021-06-05 20:27:57 +08:00
parent d3cf71dad8
commit abc5162bca
10 changed files with 100 additions and 14 deletions

View File

@@ -9,11 +9,12 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions"
"net/url"
"regexp"
"strings"
)
// 添加源站
// AddPopupAction 添加源站
type AddPopupAction struct {
actionutils.ParentAction
}
@@ -64,10 +65,27 @@ func (this *AddPopupAction) RunPost(params struct {
Field("addr", params.Addr).
Require("请输入源站地址")
addr := regexp.MustCompile(`\s+`).ReplaceAllString(params.Addr, "")
portIndex := strings.LastIndex(params.Addr, ":")
addr := params.Addr
// 是否是完整的地址
if params.Protocol == "http" || params.Protocol == "https" {
u, err := url.Parse(addr)
if err == nil {
addr = u.Host
}
}
addr = regexp.MustCompile(`\s+`).ReplaceAllString(addr, "")
portIndex := strings.LastIndex(addr, ":")
if portIndex < 0 {
this.Fail("地址中需要带有端口")
if params.Protocol == "http" {
addr += ":80"
} else if params.Protocol == "https" {
addr += ":443"
} else {
this.Fail("地址中需要带有端口")
}
portIndex = strings.LastIndex(addr, ":")
}
host := addr[:portIndex]
port := addr[portIndex+1:]

View File

@@ -10,11 +10,12 @@ import (
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
"net/url"
"regexp"
"strings"
)
// 修改源站
// UpdatePopupAction 修改源站
type UpdatePopupAction struct {
actionutils.ParentAction
}
@@ -118,10 +119,27 @@ func (this *UpdatePopupAction) RunPost(params struct {
Field("addr", params.Addr).
Require("请输入源站地址")
addr := regexp.MustCompile(`\s+`).ReplaceAllString(params.Addr, "")
portIndex := strings.LastIndex(params.Addr, ":")
addr := params.Addr
// 是否是完整的地址
if params.Protocol == "http" || params.Protocol == "https" {
u, err := url.Parse(addr)
if err == nil {
addr = u.Host
}
}
addr = regexp.MustCompile(`\s+`).ReplaceAllString(addr, "")
portIndex := strings.LastIndex(addr, ":")
if portIndex < 0 {
this.Fail("地址中需要带有端口")
if params.Protocol == "http" {
addr += ":80"
} else if params.Protocol == "https" {
addr += ":443"
} else {
this.Fail("地址中需要带有端口")
}
portIndex = strings.LastIndex(addr, ":")
}
host := addr[:portIndex]
port := addr[portIndex+1:]