mirror of https://github.com/1Panel-dev/1Panel
fix: 网站,名称、代号增加限制
parent
5f321f91a9
commit
92e7617304
|
@ -17,12 +17,18 @@ func (w WebSiteRepo) WithAppInstallId(appInstallId uint) DBOption {
|
|||
}
|
||||
}
|
||||
|
||||
func (w WebSiteRepo) WithByDomain(domain string) DBOption {
|
||||
func (w WebSiteRepo) WithDomain(domain string) DBOption {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("primary_domain = ?", domain)
|
||||
}
|
||||
}
|
||||
|
||||
func (w WebSiteRepo) WithAlias(alias string) DBOption {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("alias = ?", alias)
|
||||
}
|
||||
}
|
||||
|
||||
func (w WebSiteRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebSite, error) {
|
||||
var websites []model.WebSite
|
||||
db := getDb(opts...).Model(&model.WebSite{})
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -59,6 +60,16 @@ func (w WebsiteService) PageWebSite(req dto.WebSiteReq) (int64, []dto.WebSiteDTO
|
|||
|
||||
func (w WebsiteService) CreateWebsite(create dto.WebSiteCreate) error {
|
||||
|
||||
if exist, _ := websiteRepo.GetBy(websiteRepo.WithDomain(create.PrimaryDomain)); len(exist) > 0 {
|
||||
return buserr.New(constant.ErrNameIsExist)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
defaultDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate)
|
||||
website := &model.WebSite{
|
||||
PrimaryDomain: create.PrimaryDomain,
|
||||
|
@ -167,7 +178,7 @@ func (w WebsiteService) RecoverByUpload(req dto.WebSiteRecoverByFile) error {
|
|||
return errors.New("上传文件与选中网站不匹配,无法恢复")
|
||||
}
|
||||
|
||||
website, err := websiteRepo.GetFirst(websiteRepo.WithByDomain(req.WebsiteName))
|
||||
website, err := websiteRepo.GetFirst(websiteRepo.WithDomain(req.WebsiteName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -179,7 +190,7 @@ func (w WebsiteService) RecoverByUpload(req dto.WebSiteRecoverByFile) error {
|
|||
}
|
||||
|
||||
func (w WebsiteService) Recover(req dto.WebSiteRecover) error {
|
||||
website, err := websiteRepo.GetFirst(websiteRepo.WithByDomain(req.WebsiteName))
|
||||
website, err := websiteRepo.GetFirst(websiteRepo.WithDomain(req.WebsiteName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -506,7 +517,7 @@ type WebSiteInfo struct {
|
|||
}
|
||||
|
||||
func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName string) error {
|
||||
website, err := websiteRepo.GetFirst(websiteRepo.WithByDomain(domain))
|
||||
website, err := websiteRepo.GetFirst(websiteRepo.WithDomain(domain))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -52,3 +52,10 @@ var (
|
|||
ErrFileCanNotRead = "ErrFileCanNotRead"
|
||||
ErrFileToLarge = "ErrFileToLarge"
|
||||
)
|
||||
|
||||
//website
|
||||
|
||||
var (
|
||||
ErrDomainIsExist = "ErrDomainIsExist"
|
||||
ErrAliasIsExist = "ErrAliasIsExist"
|
||||
)
|
||||
|
|
|
@ -26,4 +26,8 @@ ErrAppRequired: "{{ .detail }} app is required"
|
|||
|
||||
#file
|
||||
ErrFileCanNotRead: "File can not read"
|
||||
ErrFileToLarge: "file is too large"
|
||||
ErrFileToLarge: "file is too large"
|
||||
|
||||
#website
|
||||
ErrDomainIsExist: "Domain is already exist"
|
||||
ErrAliasIsExist: "Alias is already exist"
|
|
@ -26,4 +26,8 @@ ErrAppRequired: "请先安装 {{ .detail }} 应用"
|
|||
|
||||
#file
|
||||
ErrFileCanNotRead: "文件不可读"
|
||||
ErrFileToLarge: "文件超过10M,无法打开"
|
||||
ErrFileToLarge: "文件超过10M,无法打开"
|
||||
|
||||
#website
|
||||
ErrDomainIsExist: "域名已存在"
|
||||
ErrAliasIsExist: "代号已存在"
|
Loading…
Reference in New Issue