提交 ac4cb15c 编写于 作者: 雨爱无痕

Fix issue

上级 c32fd36d
......@@ -2,6 +2,7 @@ package zentaoHelper
import (
"fmt"
"net/url"
"regexp"
"strings"
......@@ -86,7 +87,7 @@ func ListLang() (langs []serverDomain.ZentaoLang, err error) {
return
}
func FixSiteUrl(url string) (ret string) {
func FixUrl(url string) (ret string) {
regx := regexp.MustCompile(`(http|https):\/\/.+`)
result := regx.FindStringSubmatch(url)
if result == nil {
......@@ -108,3 +109,16 @@ func FixSiteUrl(url string) (ret string) {
return
}
func FixSiteUrl(orginUrl string) (ret string) {
u, _ := url.Parse(orginUrl)
ret = fmt.Sprintf("%s://%s", u.Scheme, u.Host)
if u.Port() != "" {
ret += ":" + u.Port()
}
ret += "/"
if u.Path[:8] == "/zentao/" {
ret = ret + "zentao/"
}
return
}
......@@ -29,7 +29,7 @@ func (s *ProxyService) Get(id uint) (proxy model.Proxy, err error) {
}
func (s *ProxyService) Create(proxy model.Proxy) (id uint, err error) {
proxy.Path = zentaoHelper.FixSiteUrl(proxy.Path)
proxy.Path = zentaoHelper.FixUrl(proxy.Path)
if proxy.Path == "" {
err = errors.New(i118Utils.Sprintf("wrong_url_format"))
return
......@@ -44,7 +44,7 @@ func (s *ProxyService) Create(proxy model.Proxy) (id uint, err error) {
}
func (s *ProxyService) Update(proxy model.Proxy) (err error) {
proxy.Path = zentaoHelper.FixSiteUrl(proxy.Path)
proxy.Path = zentaoHelper.FixUrl(proxy.Path)
if proxy.Path == "" {
err = errors.New(i118Utils.Sprintf("wrong_url_format"))
return
......
......@@ -29,7 +29,7 @@ func (s *ServerService) Get(id uint) (server model.Server, err error) {
}
func (s *ServerService) Create(server model.Server) (id uint, err error) {
server.Path = zentaoHelper.FixSiteUrl(server.Path)
server.Path = zentaoHelper.FixUrl(server.Path)
if server.Path == "" {
err = errors.New(i118Utils.Sprintf("wrong_url_format"))
return
......@@ -44,7 +44,7 @@ func (s *ServerService) Create(server model.Server) (id uint, err error) {
}
func (s *ServerService) Update(server model.Server) (err error) {
server.Path = zentaoHelper.FixSiteUrl(server.Path)
server.Path = zentaoHelper.FixUrl(server.Path)
if server.Path == "" {
err = errors.New(i118Utils.Sprintf("wrong_url_format"))
return
......
......@@ -51,16 +51,10 @@ func (s *SiteService) Create(site model.Site) (id uint, isDuplicate bool, err er
}
site.Url = fileUtils.AddUrlPathSepIfNeeded(site.Url)
config := configHelper.LoadBySite(site)
err = zentaoHelper.Login(config)
if err != nil {
config.Url += "zentao/"
site.Url += "zentao/"
err = zentaoHelper.Login(config)
if err != nil {
return
}
return
}
id, isDuplicate, err = s.SiteRepo.Create(&site)
......@@ -74,18 +68,10 @@ func (s *SiteService) Update(site model.Site) (isDuplicate bool, err error) {
err = errors.New("url not right")
return
}
site.Url = fileUtils.AddUrlPathSepIfNeeded(site.Url)
config := configHelper.LoadBySite(site)
err = zentaoHelper.Login(config)
if err != nil {
config.Url += "zentao/"
site.Url += "zentao/"
err = zentaoHelper.Login(config)
if err != nil {
return
}
return
}
isDuplicate, err = s.SiteRepo.Update(site)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册