提交 6e6cc5f3 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

update zentao url parse

上级 a22f8f36
......@@ -12,7 +12,6 @@ import (
scriptHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/script"
zentaoHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/zentao"
commonUtils "github.com/easysoft/zentaoatf/pkg/lib/common"
fileUtils "github.com/easysoft/zentaoatf/pkg/lib/file"
i118Utils "github.com/easysoft/zentaoatf/pkg/lib/i118"
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
stdinUtils "github.com/easysoft/zentaoatf/pkg/lib/stdin"
......@@ -127,17 +126,22 @@ func InputForSet(dir string) {
SetZentao:
conf.Url = stdinUtils.GetInput("((http|https)://.*)", conf.Url, "enter_url", conf.Url)
conf.Url = zentaoHelper.FixSiteUrl(conf.Url)
conf.Url = fileUtils.AddUrlPathSepIfNeeded(conf.Url)
conf.Username = stdinUtils.GetInput("(.{2,})", conf.Username, "enter_account", conf.Username)
conf.Password = stdinUtils.GetInput("(.{2,})", conf.Password, "enter_password", conf.Password)
url1, url2 := zentaoHelper.FixSiteUrl(conf.Url)
conf.Url = url1
err := zentaoHelper.Login(conf)
if err != nil {
conf.Url = url2
err = zentaoHelper.Login(conf)
if err != nil {
goto SetZentao
}
}
}
if commonUtils.IsWin() {
var configInterpreter bool
......
......@@ -2,6 +2,7 @@ package zentaoHelper
import (
"fmt"
fileUtils "github.com/easysoft/zentaoatf/pkg/lib/file"
"net/url"
"regexp"
"strings"
......@@ -110,12 +111,20 @@ func FixUrl(url string) (ret string) {
return
}
func FixSiteUrl(orginUrl string) (ret string) {
func FixSiteUrl(orginUrl string) (url1, url2 string) {
u, _ := url.Parse(orginUrl)
ret = fmt.Sprintf("%s://%s", u.Scheme, u.Host)
ret += "/"
if len(u.Path) >= 7 && u.Path[:7] == "/zentao" {
ret = ret + "zentao/"
url1 = fmt.Sprintf("%s://%s", u.Scheme, u.Host)
url1 += "/"
pth := strings.Replace(orginUrl, url1, "", -1)
pth = strings.TrimLeft(pth, "/")
arr := strings.Split(pth, "/")
if len(arr) > 1 {
url2 = url1 + arr[0]
}
url1 = fileUtils.AddUrlPathSepIfNeeded(url1)
url2 = fileUtils.AddUrlPathSepIfNeeded(url2)
return
}
......@@ -10,7 +10,6 @@ import (
"github.com/easysoft/zentaoatf/internal/server/modules/v1/model"
"github.com/easysoft/zentaoatf/internal/server/modules/v1/repo"
"github.com/easysoft/zentaoatf/pkg/domain"
fileUtils "github.com/easysoft/zentaoatf/pkg/lib/file"
)
type SiteService struct {
......@@ -44,18 +43,24 @@ func (s *SiteService) GetDomainObject(id uint) (site serverDomain.ZentaoSite, er
}
func (s *SiteService) Create(site model.Site) (id uint, isDuplicate bool, err error) {
site.Url = zentaoHelper.FixSiteUrl(site.Url)
if site.Url == "" {
url1, url2 := zentaoHelper.FixSiteUrl(site.Url)
if url1 == "" {
err = errors.New("url not right")
return
}
site.Url = fileUtils.AddUrlPathSepIfNeeded(site.Url)
site.Url = url1
config := configHelper.LoadBySite(site)
err = zentaoHelper.Login(config)
if err != nil {
site.Url = url2
config := configHelper.LoadBySite(site)
err = zentaoHelper.Login(config)
if err != nil {
return
}
}
id, isDuplicate, err = s.SiteRepo.Create(&site)
......@@ -63,16 +68,24 @@ func (s *SiteService) Create(site model.Site) (id uint, isDuplicate bool, err er
}
func (s *SiteService) Update(site model.Site) (isDuplicate bool, err error) {
site.Url = zentaoHelper.FixSiteUrl(site.Url)
if site.Url == "" {
url1, url2 := zentaoHelper.FixSiteUrl(site.Url)
if url1 == "" {
err = errors.New("url not right")
return
}
site.Url = url1
config := configHelper.LoadBySite(site)
err = zentaoHelper.Login(config)
if err != nil {
site.Url = url2
config := configHelper.LoadBySite(site)
err = zentaoHelper.Login(config)
if err != nil {
return
}
}
isDuplicate, err = s.SiteRepo.Update(site)
if isDuplicate || err != nil {
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册