mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-17 12:58:51 +08:00
fix: 解决可以创建同名网站的问题 (#2701)
This commit is contained in:
parent
de2cac5ebc
commit
18de677636
1 changed files with 19 additions and 6 deletions
|
|
@ -171,22 +171,35 @@ func (w WebsiteService) GetWebsites() ([]response.WebsiteDTO, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err 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)
|
return buserr.New(constant.ErrDomainIsExist)
|
||||||
}
|
}
|
||||||
if exist, _ := websiteRepo.GetBy(websiteRepo.WithAlias(create.Alias)); len(exist) > 0 {
|
if exist, _ := websiteRepo.GetBy(websiteRepo.WithAlias(create.Alias)); len(exist) > 0 {
|
||||||
return buserr.New(constant.ErrAliasIsExist)
|
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)
|
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defaultHttpPort := nginxInstall.HttpPort
|
defaultHttpPort := nginxInstall.HttpPort
|
||||||
primaryDomainArray := strings.Split(create.PrimaryDomain, ":")
|
if len(primaryDomainArray) > 1 {
|
||||||
primaryDomain := primaryDomainArray[0]
|
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 (
|
var (
|
||||||
domains []model.WebsiteDomain
|
domains []model.WebsiteDomain
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue