mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-19 05:39:26 +08:00
fix: 解决安装redis-commander没有同步密码的BUG,安装APP增加名称唯一性校验
This commit is contained in:
parent
1090047e55
commit
7de0284e81
@ -104,8 +104,9 @@ type PortUpdate struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AppService struct {
|
type AppService struct {
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
|
Config interface{} `json:"config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppDatabase struct {
|
type AppDatabase struct {
|
||||||
|
@ -7,17 +7,16 @@ import (
|
|||||||
|
|
||||||
type AppInstall struct {
|
type AppInstall struct {
|
||||||
BaseModel
|
BaseModel
|
||||||
Name string `json:"name" gorm:"type:varchar(64);not null"`
|
Name string `json:"name" gorm:"type:varchar(64);not null;UNIQUE"`
|
||||||
AppId uint `json:"appId" gorm:"type:integer;not null"`
|
AppId uint `json:"appId" gorm:"type:integer;not null"`
|
||||||
AppDetailId uint `json:"appDetailId" gorm:"type:integer;not null"`
|
AppDetailId uint `json:"appDetailId" gorm:"type:integer;not null"`
|
||||||
Version string `json:"version" gorm:"type:varchar(64);not null"`
|
Version string `json:"version" gorm:"type:varchar(64);not null"`
|
||||||
Param string `json:"param" gorm:"type:longtext;"`
|
Param string `json:"param" gorm:"type:longtext;"`
|
||||||
Env string `json:"env" gorm:"type:longtext;"`
|
Env string `json:"env" gorm:"type:longtext;"`
|
||||||
DockerCompose string `json:"dockerCompose" gorm:"type:longtext;"`
|
DockerCompose string `json:"dockerCompose" gorm:"type:longtext;"`
|
||||||
Status string `json:"status" gorm:"type:varchar(256);not null"`
|
Status string `json:"status" gorm:"type:varchar(256);not null"`
|
||||||
Description string `json:"description" gorm:"type:varchar(256);"`
|
Description string `json:"description" gorm:"type:varchar(256);"`
|
||||||
Message string `json:"message" gorm:"type:longtext;"`
|
Message string `json:"message" gorm:"type:longtext;"`
|
||||||
//CanUpdate bool `json:"canUpdate"`
|
|
||||||
ContainerName string `json:"containerName" gorm:"type:varchar(256);not null"`
|
ContainerName string `json:"containerName" gorm:"type:varchar(256);not null"`
|
||||||
ServiceName string `json:"serviceName" gorm:"type:varchar(256);not null"`
|
ServiceName string `json:"serviceName" gorm:"type:varchar(256);not null"`
|
||||||
HttpPort int `json:"httpPort" gorm:"type:integer;not null"`
|
HttpPort int `json:"httpPort" gorm:"type:integer;not null"`
|
||||||
|
@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -139,6 +140,11 @@ func (a AppService) GetAppDetail(appId uint, version string) (dto.AppDetailDTO,
|
|||||||
|
|
||||||
func (a AppService) Install(name string, appDetailId uint, params map[string]interface{}) (*model.AppInstall, error) {
|
func (a AppService) Install(name string, appDetailId uint, params map[string]interface{}) (*model.AppInstall, error) {
|
||||||
|
|
||||||
|
list, _ := appInstallRepo.GetBy(commonRepo.WithByName(name))
|
||||||
|
if len(list) > 0 {
|
||||||
|
return nil, buserr.New(constant.ErrNameIsExist, "", nil)
|
||||||
|
}
|
||||||
|
|
||||||
httpPort, err := checkPort("PANEL_APP_PORT_HTTP", params)
|
httpPort, err := checkPort("PANEL_APP_PORT_HTTP", params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -210,9 +211,14 @@ func (a AppInstallService) GetServices(key string) ([]dto.AppService, error) {
|
|||||||
}
|
}
|
||||||
var res []dto.AppService
|
var res []dto.AppService
|
||||||
for _, install := range installs {
|
for _, install := range installs {
|
||||||
|
paramMap := make(map[string]string)
|
||||||
|
if install.Param != "" {
|
||||||
|
_ = json.Unmarshal([]byte(install.Param), ¶mMap)
|
||||||
|
}
|
||||||
res = append(res, dto.AppService{
|
res = append(res, dto.AppService{
|
||||||
Label: install.Name,
|
Label: install.Name,
|
||||||
Value: install.ServiceName,
|
Value: install.ServiceName,
|
||||||
|
Config: paramMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
|
@ -436,20 +436,21 @@ func handleMap(params map[string]interface{}, envParams map[string]string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func copyAppData(key, version, installName string, params map[string]interface{}) (err error) {
|
func copyAppData(key, version, installName string, params map[string]interface{}) (err error) {
|
||||||
resourceDir := path.Join(constant.AppResourceDir, key, "versions", version)
|
|
||||||
installDir := path.Join(constant.AppInstallDir, key)
|
|
||||||
installVersionDir := path.Join(installDir, version)
|
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
if fileOp.Stat(installVersionDir) {
|
resourceDir := path.Join(constant.AppResourceDir, key, "versions", version)
|
||||||
if err = fileOp.DeleteDir(installVersionDir); err != nil {
|
installAppDir := path.Join(constant.AppInstallDir, key)
|
||||||
|
if !fileOp.Stat(installAppDir) {
|
||||||
|
if err = fileOp.CreateDir(installAppDir, 0755); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = fileOp.Copy(resourceDir, installVersionDir); err != nil {
|
appDir := path.Join(installAppDir, installName)
|
||||||
return
|
if fileOp.Stat(appDir) {
|
||||||
|
if err = fileOp.DeleteDir(appDir); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
appDir := path.Join(installDir, installName)
|
if err = fileOp.Copy(resourceDir, appDir); err != nil {
|
||||||
if err = fileOp.Rename(installVersionDir, appDir); err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
envPath := path.Join(appDir, ".env")
|
envPath := path.Join(appDir, ".env")
|
||||||
|
@ -40,6 +40,7 @@ var (
|
|||||||
ErrTypeNotLogin = "ErrNotLogin"
|
ErrTypeNotLogin = "ErrNotLogin"
|
||||||
ErrTypePasswordExpired = "ErrPasswordExpired"
|
ErrTypePasswordExpired = "ErrPasswordExpired"
|
||||||
ErrTypeNotSafety = "ErrNotSafety"
|
ErrTypeNotSafety = "ErrNotSafety"
|
||||||
|
ErrNameIsExist = "ErrNameIsExist"
|
||||||
)
|
)
|
||||||
|
|
||||||
// app
|
// app
|
||||||
|
@ -14,6 +14,9 @@ ErrPasswordExpired: "The current password has expired: {{ .detail }}"
|
|||||||
ErrNotSupportType: "The system does not support the current type: {{ .detail }}"
|
ErrNotSupportType: "The system does not support the current type: {{ .detail }}"
|
||||||
|
|
||||||
|
|
||||||
|
#common
|
||||||
|
ErrNameIsExist: "Name is already exist"
|
||||||
|
|
||||||
#app
|
#app
|
||||||
ErrPortInUsed: "{{ .detail }} port already in use"
|
ErrPortInUsed: "{{ .detail }} port already in use"
|
||||||
ErrAppLimit: "App exceeds install limit"
|
ErrAppLimit: "App exceeds install limit"
|
||||||
|
@ -14,6 +14,9 @@ ErrPasswordExpired: "当前密码已过期: {{ .detail }}"
|
|||||||
ErrNotSupportType: "系统暂不支持当前类型: {{ .detail }}"
|
ErrNotSupportType: "系统暂不支持当前类型: {{ .detail }}"
|
||||||
|
|
||||||
|
|
||||||
|
#common
|
||||||
|
ErrNameIsExist: "名称已存在"
|
||||||
|
|
||||||
#app
|
#app
|
||||||
ErrPortInUsed: "{{ .detail }} 已被占用!"
|
ErrPortInUsed: "{{ .detail }} 已被占用!"
|
||||||
ErrAppLimit: "应用超出安装数量限制"
|
ErrAppLimit: "应用超出安装数量限制"
|
||||||
|
@ -117,6 +117,7 @@ export namespace App {
|
|||||||
export interface AppService {
|
export interface AppService {
|
||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
|
config?: Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppBackupReq extends ReqPage {
|
export interface AppBackupReq extends ReqPage {
|
||||||
|
@ -51,7 +51,7 @@ export const SyncInstalledApp = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const GetAppService = (key: string | undefined) => {
|
export const GetAppService = (key: string | undefined) => {
|
||||||
return http.get<any>(`apps/services/${key}`);
|
return http.get<App.AppService[]>(`apps/services/${key}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GetAppBackups = (info: App.AppBackupReq) => {
|
export const GetAppBackups = (info: App.AppBackupReq) => {
|
||||||
|
@ -15,7 +15,11 @@
|
|||||||
show-password
|
show-password
|
||||||
@change="updateParam"
|
@change="updateParam"
|
||||||
></el-input>
|
></el-input>
|
||||||
<el-select v-model="form[p.envKey]" v-if="p.type == 'service'" @change="updateParam">
|
<el-select
|
||||||
|
v-model="form[p.envKey]"
|
||||||
|
v-if="p.type == 'service'"
|
||||||
|
@change="changeService(form[p.envKey], p.services)"
|
||||||
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="service in p.services"
|
v-for="service in p.services"
|
||||||
:key="service.label"
|
:key="service.label"
|
||||||
@ -112,8 +116,6 @@ const handleParams = () => {
|
|||||||
emit('update:rules', rules);
|
emit('update:rules', rules);
|
||||||
updateParam();
|
updateParam();
|
||||||
}
|
}
|
||||||
console.log(rules);
|
|
||||||
console.log(paramObjs);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -122,11 +124,27 @@ const getServices = async (envKey: string, key: string | undefined, pObj: ParamO
|
|||||||
pObj.services = res.data;
|
pObj.services = res.data;
|
||||||
if (res.data.length > 0) {
|
if (res.data.length > 0) {
|
||||||
form[envKey] = res.data[0].value;
|
form[envKey] = res.data[0].value;
|
||||||
|
if (res.data[0].config) {
|
||||||
|
Object.entries(res.data[0].config).forEach(([k, v]) => {
|
||||||
|
form[k] = v;
|
||||||
|
});
|
||||||
|
}
|
||||||
updateParam();
|
updateParam();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const changeService = (value: string, services: App.AppService[]) => {
|
||||||
|
services.forEach((item) => {
|
||||||
|
if (item.value === value) {
|
||||||
|
Object.entries(item.config).forEach(([k, v]) => {
|
||||||
|
form[k] = v;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
updateParam();
|
||||||
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
handleParams();
|
handleParams();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user