Browse Source

feat: 删除无用代码 (#5757)

pull/5760/head
zhengkunwang 4 months ago committed by GitHub
parent
commit
c0b6a06fb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 92
      backend/app/service/website.go

92
backend/app/service/website.go

@ -9,7 +9,6 @@ import (
"encoding/pem"
"errors"
"fmt"
"github.com/1Panel-dev/1Panel/backend/app/task"
"os"
"path"
"reflect"
@ -207,34 +206,13 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
if exist, _ := websiteRepo.GetBy(websiteRepo.WithAlias(alias)); len(exist) > 0 {
return buserr.New(constant.ErrAliasIsExist)
}
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil {
return err
}
defaultHttpPort := nginxInstall.HttpPort
var (
existInstall model.AppInstall
runtime *model.Runtime
appInstall *model.AppInstall
proxy string
)
switch create.Type {
case constant.Deployment:
if create.AppType != constant.NewApp {
existInstall, err = appInstallRepo.GetFirst(commonRepo.WithByID(create.AppInstallID))
if err != nil {
return err
}
}
case constant.Runtime:
runtime, err = runtimeRepo.GetFirst(commonRepo.WithByID(create.RuntimeID))
if err != nil {
return err
}
}
var (
otherDomains []model.WebsiteDomain
domains []model.WebsiteDomain
@ -266,15 +244,13 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
IPV6: create.IPV6,
}
websiteTask, err := task.NewTask("创建网站", "website")
if err != nil {
return err
}
var (
appInstall *model.AppInstall
runtime *model.Runtime
)
switch create.Type {
case constant.Deployment:
if create.AppType == constant.NewApp {
deleteApp := func() {
defer func() {
if err != nil {
if website.AppInstallID > 0 {
req := request.AppInstalledOperate{
InstallId: website.AppInstallID,
@ -286,7 +262,12 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
}
}
}
installApp := func() error {
}()
var proxy string
switch create.Type {
case constant.Deployment:
if create.AppType == constant.NewApp {
var (
req request.AppInstallCreate
install *model.AppInstall
@ -305,20 +286,25 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
appInstall = install
website.AppInstallID = install.ID
website.Proxy = fmt.Sprintf("127.0.0.1:%d", appInstall.HttpPort)
return nil
}
websiteTask.AddSubTask("安装应用", installApp, deleteApp)
} else {
appInstall = &existInstall
var install model.AppInstall
install, err = appInstallRepo.GetFirst(commonRepo.WithByID(create.AppInstallID))
if err != nil {
return err
}
appInstall = &install
website.AppInstallID = appInstall.ID
website.Proxy = fmt.Sprintf("127.0.0.1:%d", appInstall.HttpPort)
}
case constant.Runtime:
runtime, err = runtimeRepo.GetFirst(commonRepo.WithByID(create.RuntimeID))
if err != nil {
return err
}
website.RuntimeID = runtime.ID
switch runtime.Type {
case constant.RuntimePHP:
if runtime.Resource == constant.ResourceAppstore {
installApp := func() error {
var (
req request.AppInstallCreate
install *model.AppInstall
@ -340,9 +326,6 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
website.AppInstallID = install.ID
appInstall = install
website.Proxy = fmt.Sprintf("127.0.0.1:%d", appInstall.HttpPort)
return nil
}
websiteTask.AddSubTask("创建运行环境", installApp, nil)
} else {
website.ProxyType = create.ProxyType
if website.ProxyType == constant.RuntimeProxyUnix {
@ -358,13 +341,23 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
}
}
configNginx := func() error {
if err = configDefaultNginx(website, domains, appInstall, runtime); err != nil {
return err
}
if len(create.FtpUser) != 0 && len(create.FtpPassword) != 0 {
indexDir := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "index")
itemID, err := NewIFtpService().Create(dto.FtpCreate{User: create.FtpUser, Password: create.FtpPassword, Path: indexDir})
if err != nil {
global.LOG.Errorf("create ftp for website failed, err: %v", err)
}
website.FtpID = itemID
}
if err = createWafConfig(website, domains); err != nil {
return err
}
tx, ctx := helper.GetTxAndContext()
defer tx.Rollback()
if err = websiteRepo.Create(ctx, website); err != nil {
@ -379,23 +372,6 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
tx.Commit()
return nil
}
websiteTask.AddSubTask("配置 OpenResty", configNginx, nil)
if len(create.FtpUser) != 0 && len(create.FtpPassword) != 0 {
createFtp := func() error {
indexDir := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "index")
itemID, err := NewIFtpService().Create(dto.FtpCreate{User: create.FtpUser, Password: create.FtpPassword, Path: indexDir})
if err != nil {
websiteTask.Logger.Printf("create ftp for website failed, err: %v", err)
}
website.FtpID = itemID
return nil
}
websiteTask.AddSubTask("创建 FTP", createFtp, nil)
}
return websiteTask.Execute()
}
func (w WebsiteService) OpWebsite(req request.WebsiteOp) error {
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID))

Loading…
Cancel
Save