From 18de677636341bde4f76e8c67a648428c454f168 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Fri, 27 Oct 2023 12:02:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=90=8C=E5=90=8D=E7=BD=91=E7=AB=99=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#2701)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/website.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/backend/app/service/website.go b/backend/app/service/website.go index fad825762..85c6285b6 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -171,22 +171,35 @@ func (w WebsiteService) GetWebsites() ([]response.WebsiteDTO, error) { } func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) { - if exist, _ := websiteRepo.GetBy(websiteRepo.WithDomain(create.PrimaryDomain)); len(exist) > 0 { + primaryDomainArray := strings.Split(create.PrimaryDomain, ":") + primaryDomain := primaryDomainArray[0] + + if exist, _ := websiteRepo.GetBy(websiteRepo.WithDomain(primaryDomain)); len(exist) > 0 { return buserr.New(constant.ErrDomainIsExist) } if exist, _ := websiteRepo.GetBy(websiteRepo.WithAlias(create.Alias)); len(exist) > 0 { return buserr.New(constant.ErrAliasIsExist) } - if exist, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithDomain(create.PrimaryDomain)); len(exist) > 0 { - return buserr.New(constant.ErrDomainIsExist) - } + nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) if err != nil { return err } defaultHttpPort := nginxInstall.HttpPort - primaryDomainArray := strings.Split(create.PrimaryDomain, ":") - primaryDomain := primaryDomainArray[0] + if len(primaryDomainArray) > 1 { + portStr := primaryDomainArray[1] + portN, err := strconv.Atoi(portStr) + if err != nil { + return err + } + if exist, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithDomain(primaryDomain), websiteDomainRepo.WithPort(portN)); len(exist) > 0 { + return buserr.New(constant.ErrDomainIsExist) + } + } else { + if exist, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithDomain(primaryDomain), websiteDomainRepo.WithPort(defaultHttpPort)); len(exist) > 0 { + return buserr.New(constant.ErrDomainIsExist) + } + } var ( domains []model.WebsiteDomain