1
0
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:
zhengkunwang223 2022-12-02 10:31:07 +08:00 committed by zhengkunwang223
parent 1090047e55
commit 7de0284e81
11 changed files with 67 additions and 28 deletions

View File

@ -106,6 +106,7 @@ 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 {

View File

@ -7,7 +7,7 @@ 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"`
@ -17,7 +17,6 @@ type AppInstall struct {
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"`

View File

@ -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

View File

@ -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), &paramMap)
}
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

View File

@ -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)
if fileOp.Stat(appDir) {
if err = fileOp.DeleteDir(appDir); err != nil {
return return
} }
appDir := path.Join(installDir, installName) }
if err = fileOp.Rename(installVersionDir, appDir); err != nil { if err = fileOp.Copy(resourceDir, appDir); err != nil {
return return
} }
envPath := path.Join(appDir, ".env") envPath := path.Join(appDir, ".env")

View File

@ -40,6 +40,7 @@ var (
ErrTypeNotLogin = "ErrNotLogin" ErrTypeNotLogin = "ErrNotLogin"
ErrTypePasswordExpired = "ErrPasswordExpired" ErrTypePasswordExpired = "ErrPasswordExpired"
ErrTypeNotSafety = "ErrNotSafety" ErrTypeNotSafety = "ErrNotSafety"
ErrNameIsExist = "ErrNameIsExist"
) )
// app // app

View File

@ -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"

View File

@ -14,6 +14,9 @@ ErrPasswordExpired: "当前密码已过期: {{ .detail }}"
ErrNotSupportType: "系统暂不支持当前类型: {{ .detail }}" ErrNotSupportType: "系统暂不支持当前类型: {{ .detail }}"
#common
ErrNameIsExist: "名称已存在"
#app #app
ErrPortInUsed: "{{ .detail }} 已被占用!" ErrPortInUsed: "{{ .detail }} 已被占用!"
ErrAppLimit: "应用超出安装数量限制" ErrAppLimit: "应用超出安装数量限制"

View File

@ -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 {

View File

@ -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) => {

View File

@ -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();
}); });