mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2024-12-04 12:59:52 +08:00
feat: 优化网站创建流程 (#591)
This commit is contained in:
parent
42531dae5a
commit
b16308b7ea
@ -78,14 +78,12 @@ func (b *BaseApi) CreateWebsite(c *gin.Context) {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||
return
|
||||
}
|
||||
tx, ctx := helper.GetTxAndContext()
|
||||
err := websiteService.CreateWebsite(ctx, req)
|
||||
|
||||
err := websiteService.CreateWebsite(req)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||
return
|
||||
}
|
||||
tx.Commit()
|
||||
helper.SuccessWithData(c, nil)
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
@ -33,7 +34,7 @@ type WebsiteService struct {
|
||||
type IWebsiteService interface {
|
||||
PageWebsite(req request.WebsiteSearch) (int64, []response.WebsiteDTO, error)
|
||||
GetWebsites() ([]response.WebsiteDTO, error)
|
||||
CreateWebsite(ctx context.Context, create request.WebsiteCreate) error
|
||||
CreateWebsite(create request.WebsiteCreate) error
|
||||
OpWebsite(req request.WebsiteOp) error
|
||||
GetWebsiteOptions() ([]string, error)
|
||||
UpdateWebsite(req request.WebsiteUpdate) error
|
||||
@ -119,7 +120,7 @@ func (w WebsiteService) GetWebsites() ([]response.WebsiteDTO, error) {
|
||||
return websiteDTOs, nil
|
||||
}
|
||||
|
||||
func (w WebsiteService) CreateWebsite(ctx context.Context, 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 {
|
||||
return buserr.New(constant.ErrDomainIsExist)
|
||||
}
|
||||
@ -158,7 +159,7 @@ func (w WebsiteService) CreateWebsite(ctx context.Context, create request.Websit
|
||||
Operate: constant.Delete,
|
||||
ForceDelete: true,
|
||||
}
|
||||
if err := NewIAppInstalledService().Operate(ctx, req); err != nil {
|
||||
if err := NewIAppInstalledService().Operate(context.Background(), req); err != nil {
|
||||
global.LOG.Errorf(err.Error())
|
||||
}
|
||||
}
|
||||
@ -227,6 +228,8 @@ func (w WebsiteService) CreateWebsite(ctx context.Context, create request.Websit
|
||||
}
|
||||
}
|
||||
|
||||
tx, ctx := helper.GetTxAndContext()
|
||||
defer tx.Rollback()
|
||||
if err = websiteRepo.Create(ctx, website); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -252,7 +255,11 @@ func (w WebsiteService) CreateWebsite(ctx context.Context, create request.Websit
|
||||
return err
|
||||
}
|
||||
}
|
||||
return configDefaultNginx(website, domains, appInstall, runtime, create.RuntimeConfig)
|
||||
if err != configDefaultNginx(website, domains, appInstall, runtime, create.RuntimeConfig) {
|
||||
return err
|
||||
}
|
||||
tx.Commit()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w WebsiteService) OpWebsite(req request.WebsiteOp) error {
|
||||
|
@ -500,7 +500,7 @@ func checkIsLinkApp(website model.Website) bool {
|
||||
}
|
||||
if website.Type == constant.Runtime {
|
||||
runtime, _ := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID))
|
||||
return runtime.Resource == constant.AppResourceRemote
|
||||
return runtime.Resource == constant.ResourceAppstore
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ var (
|
||||
ErrDbUserNotValid = "ErrDbUserNotValid"
|
||||
ErrUpdateBuWebsite = "ErrUpdateBuWebsite"
|
||||
Err1PanelNetworkFailed = "Err1PanelNetworkFailed"
|
||||
ErrCmdTimeout = "ErrCmdTimeout"
|
||||
)
|
||||
|
||||
// website
|
||||
|
@ -16,6 +16,7 @@ ErrRepoNotValid: "Remote repository verification failed!"
|
||||
#common
|
||||
ErrNameIsExist: "Name is already exist"
|
||||
ErrDemoEnvironment: "Demo server, prohibit this operation!"
|
||||
ErrCmdTimeout: "Command execution timed out!"
|
||||
|
||||
#app
|
||||
ErrPortInUsed: "{{ .detail }} port already in use"
|
||||
|
@ -16,6 +16,7 @@ ErrRepoNotValid: "远程仓库校验失败!"
|
||||
#common
|
||||
ErrNameIsExist: "名称已存在"
|
||||
ErrDemoEnvironment: "演示服务器,禁止此操作!"
|
||||
ErrCmdTimeout: "命令执行超时!"
|
||||
|
||||
#app
|
||||
ErrPortInUsed: "{{ .detail }} 端口已被占用!"
|
||||
|
@ -2,16 +2,25 @@ package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Exec(cmdStr string) (string, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.Command("bash", "-c", cmdStr)
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
err := cmd.Run()
|
||||
if ctx.Err() == context.DeadlineExceeded {
|
||||
return "", buserr.New(constant.ErrCmdTimeout)
|
||||
}
|
||||
if err != nil {
|
||||
errMsg := ""
|
||||
if len(stderr.String()) != 0 {
|
||||
|
@ -105,7 +105,7 @@
|
||||
round
|
||||
size="small"
|
||||
:disabled="installed.status !== 'Running'"
|
||||
@click="openUploads(installed.app.name, installed.name)"
|
||||
@click="openUploads(installed.app.key, installed.name)"
|
||||
v-if="mode === 'installed'"
|
||||
>
|
||||
{{ $t('database.loadBackup') }}
|
||||
@ -117,7 +117,7 @@
|
||||
round
|
||||
size="small"
|
||||
:disabled="installed.status !== 'Running'"
|
||||
@click="openBackups(installed.app.name, installed.name)"
|
||||
@click="openBackups(installed.app.key, installed.name)"
|
||||
v-if="mode === 'installed'"
|
||||
>
|
||||
{{ $t('app.backup') }}
|
||||
|
Loading…
Reference in New Issue
Block a user