fix: 解决相同域名和端口可以重复添加的问题 (#2470)

This commit is contained in:
zhengkunwang 2023-10-08 06:02:15 -05:00 committed by GitHub
parent c0c65598c8
commit 7171c13e31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -463,13 +463,15 @@ func (w WebsiteService) CreateWebsiteDomain(create request.WebsiteDomainCreate)
return domainModel, err
}
if existDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithPort(create.Port)); len(existDomains) == 0 {
if existDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithDomain(create.Domain), websiteDomainRepo.WithPort(create.Port)); len(existDomains) == 0 {
if existAppInstall, _ := appInstallRepo.GetFirst(appInstallRepo.WithPort(create.Port)); !reflect.DeepEqual(existAppInstall, model.AppInstall{}) {
return domainModel, buserr.WithMap(constant.ErrPortInOtherApp, map[string]interface{}{"port": create.Port, "apps": existAppInstall.App.Name}, nil)
}
if common.ScanPort(create.Port) {
return domainModel, buserr.WithDetail(constant.ErrPortInUsed, create.Port, nil)
}
} else {
return domainModel, buserr.WithDetail(constant.ErrDomainIsExist, create.Domain, nil)
}
website, err := websiteRepo.GetFirst(commonRepo.WithByID(create.WebsiteID))
@ -479,7 +481,11 @@ func (w WebsiteService) CreateWebsiteDomain(create request.WebsiteDomainCreate)
if oldDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(create.WebsiteID), websiteDomainRepo.WithPort(create.Port)); len(oldDomains) == 0 {
ports = append(ports, create.Port)
}
domains = append(domains, create.Domain)
if oldDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(create.WebsiteID), websiteDomainRepo.WithDomain(create.Domain)); len(oldDomains) == 0 {
domains = append(domains, create.Domain)
}
if err := addListenAndServerName(website, ports, domains); err != nil {
return domainModel, err
}