Browse Source

fix: 修改数据库设置跳转路由 (#2320)

pull/2322/head
ssongliu 1 year ago committed by GitHub
parent
commit
8faa3b6e51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      backend/app/service/app.go
  2. 2
      backend/app/service/database_mysql.go
  3. 2
      frontend/src/routers/modules/database.ts

41
backend/app/service/app.go

@ -5,6 +5,14 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path"
"reflect"
"strconv"
"strings"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
@ -19,12 +27,6 @@ import (
"github.com/1Panel-dev/1Panel/backend/utils/files"
http2 "github.com/1Panel-dev/1Panel/backend/utils/http"
"gopkg.in/yaml.v3"
"io"
"net/http"
"os"
"path"
"strconv"
"strings"
)
type AppService struct {
@ -282,6 +284,12 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) (
if err != nil {
return
}
if DatabaseKeys[app.Key] > 0 {
if existDatabases, _ := databaseRepo.GetList(commonRepo.WithByName(req.Name)); len(existDatabases) > 0 {
err = buserr.New(constant.ErrRemoteExist)
return
}
}
for key := range req.Params {
if !strings.Contains(key, "PANEL_APP_PORT") {
continue
@ -389,22 +397,13 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) (
}
}
}()
if dbHost, ok := req.Params["PANEL_DB_HOST"]; ok {
var (
databaseID int
database model.Database
)
databaseID, err = strconv.Atoi(dbHost.(string))
if err != nil {
return
}
database, err = databaseRepo.Get(commonRepo.WithByID(uint(databaseID)))
if err != nil {
return
if hostName, ok := req.Params["PANEL_DB_HOST"]; ok {
database, _ := databaseRepo.Get(commonRepo.WithByName(hostName.(string)))
if !reflect.DeepEqual(database, model.Database{}) {
req.Params["PANEL_DB_HOST"] = database.Address
req.Params["PANEL_DB_PORT"] = database.Port
req.Params["PANEL_DB_HOST_NAME"] = hostName
}
req.Params["PANEL_DB_HOST"] = database.Address
req.Params["PANEL_DB_PORT"] = database.Port
req.Params["PANEL_DB_HOST_ID"] = uint(databaseID)
}
paramByte, err = json.Marshal(req.Params)
if err != nil {

2
backend/app/service/database_mysql.go

@ -150,7 +150,7 @@ func (u *MysqlService) LoadFromRemote(req dto.MysqlLoadDB) error {
return err
}
databases, err := mysqlRepo.List(databaseRepo.WithByFrom(req.From))
databases, err := mysqlRepo.List(mysqlRepo.WithByMysqlName(req.Database))
if err != nil {
return err
}

2
frontend/src/routers/modules/database.ts

@ -28,7 +28,7 @@ const databaseRouter = {
},
},
{
path: 'mysql/setting/:type/:database/:databaseID',
path: 'mysql/setting/:type/:database',
name: 'MySQL-Setting',
component: () => import('@/views/database/mysql/setting/index.vue'),
props: true,

Loading…
Cancel
Save