1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 14:08:06 +08:00

fix: 解决获取默认配置失败的问题 (#2208)

This commit is contained in:
ssongliu 2023-09-06 21:22:12 +08:00 committed by GitHub
parent add4fab794
commit c485fe2bd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 73 additions and 45 deletions

View File

@ -262,17 +262,17 @@ func (b *BaseApi) ChangeAppPort(c *gin.Context) {
// @Summary Search default config by key
// @Description 通过 key 获取应用默认配置
// @Accept json
// @Param key path string true "request"
// @Param request body dto.OperationWithNameAndType true "request"
// @Success 200 {string} content
// @Security ApiKeyAuth
// @Router /apps/installed/conf/:key [get]
// @Router /apps/installed/conf [post]
func (b *BaseApi) GetDefaultConfig(c *gin.Context) {
key := c.Param("key")
if key == "" {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
var req dto.OperationWithNameAndType
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
content, err := appInstallService.GetDefaultConfigByKey(key)
content, err := appInstallService.GetDefaultConfigByKey(req.Type, req.Name)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return

View File

@ -219,5 +219,6 @@ func (a *AppInstallRepo) LoadBaseInfo(key string, name string) (*RootInfo, error
info.Env = appInstall.Env
info.Param = appInstall.Param
info.Version = appInstall.Version
info.Key = app.Key
return &info, nil
}

View File

@ -53,7 +53,7 @@ type IAppInstallService interface {
GetUpdateVersions(installId uint) ([]dto.AppVersion, error)
GetParams(id uint) (*response.AppConfig, error)
ChangeAppPort(req request.PortUpdate) error
GetDefaultConfigByKey(key string) (string, error)
GetDefaultConfigByKey(key, name string) (string, error)
DeleteCheck(installId uint) ([]dto.AppResource, error)
GetInstallList() ([]dto.AppInstallInfo, error)
@ -572,22 +572,22 @@ func (a *AppInstallService) DeleteCheck(installId uint) ([]dto.AppResource, erro
return res, nil
}
func (a *AppInstallService) GetDefaultConfigByKey(key string) (string, error) {
appInstall, err := getAppInstallByKey(key)
func (a *AppInstallService) GetDefaultConfigByKey(key, name string) (string, error) {
baseInfo, err := appInstallRepo.LoadBaseInfo(key, name)
if err != nil {
return "", err
}
fileOp := files.NewFileOp()
filePath := path.Join(constant.AppResourceDir, "remote", appInstall.App.Key, appInstall.Version, "conf")
filePath := path.Join(constant.AppResourceDir, "remote", baseInfo.Key, baseInfo.Version, "conf")
if !fileOp.Stat(filePath) {
filePath = path.Join(constant.AppResourceDir, appInstall.App.Key, "versions", appInstall.Version, "conf")
filePath = path.Join(constant.AppResourceDir, baseInfo.Key, "versions", baseInfo.Version, "conf")
}
if !fileOp.Stat(filePath) {
return "", buserr.New(constant.ErrPathNotFound)
}
if key == constant.AppMysql {
if key == constant.AppMysql || key == constant.AppMariaDB {
filePath = path.Join(filePath, "my.cnf")
}
if key == constant.AppRedis {

View File

@ -21,6 +21,7 @@ const (
AppOpenresty = "openresty"
AppMysql = "mysql"
AppMariaDB = "mariadb"
AppRedis = "redis"
AppResourceLocal = "local"

View File

@ -34,7 +34,7 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) {
appRouter.POST("/installed/sync", baseApi.SyncInstalled)
appRouter.POST("/installed/port/change", baseApi.ChangeAppPort)
appRouter.GET("/services/:key", baseApi.GetServices)
appRouter.GET("/installed/conf/:key", baseApi.GetDefaultConfig)
appRouter.POST("/installed/conf", baseApi.GetDefaultConfig)
appRouter.GET("/installed/params/:appInstallId", baseApi.GetParams)
appRouter.POST("/installed/params/update", baseApi.UpdateInstalled)
appRouter.POST("/installed/ignore", baseApi.IgnoreUpgrade)

View File

@ -315,8 +315,8 @@ const docTemplate = `{
}
}
},
"/apps/installed/conf/:key": {
"get": {
"/apps/installed/conf": {
"post": {
"security": [
{
"ApiKeyAuth": []
@ -332,11 +332,13 @@ const docTemplate = `{
"summary": "Search default config by key",
"parameters": [
{
"type": "string",
"description": "request",
"name": "key",
"in": "path",
"required": true
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.OperationWithNameAndType"
}
}
],
"responses": {
@ -12904,6 +12906,7 @@ const docTemplate = `{
"type": "object",
"required": [
"password",
"type",
"username",
"version"
],
@ -12923,6 +12926,9 @@ const docTemplate = `{
"port": {
"type": "integer"
},
"type": {
"type": "string"
},
"username": {
"type": "string"
},

View File

@ -308,8 +308,8 @@
}
}
},
"/apps/installed/conf/:key": {
"get": {
"/apps/installed/conf": {
"post": {
"security": [
{
"ApiKeyAuth": []
@ -325,11 +325,13 @@
"summary": "Search default config by key",
"parameters": [
{
"type": "string",
"description": "request",
"name": "key",
"in": "path",
"required": true
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.OperationWithNameAndType"
}
}
],
"responses": {
@ -12897,6 +12899,7 @@
"type": "object",
"required": [
"password",
"type",
"username",
"version"
],
@ -12916,6 +12919,9 @@
"port": {
"type": "integer"
},
"type": {
"type": "string"
},
"username": {
"type": "string"
},

View File

@ -821,12 +821,15 @@ definitions:
type: string
port:
type: integer
type:
type: string
username:
type: string
version:
type: string
required:
- password
- type
- username
- version
type: object
@ -4223,17 +4226,18 @@ paths:
summary: Check app installed
tags:
- App
/apps/installed/conf/:key:
get:
/apps/installed/conf:
post:
consumes:
- application/json
description: 通过 key 获取应用默认配置
parameters:
- description: request
in: path
name: key
in: body
name: request
required: true
type: string
schema:
$ref: '#/definitions/dto.OperationWithNameAndType'
responses:
"200":
description: OK

View File

@ -82,8 +82,8 @@ export const GetAppUpdateVersions = (id: number) => {
return http.get<any>(`apps/installed/${id}/versions`);
};
export const GetAppDefaultConfig = (key: string) => {
return http.get<string>(`apps/installed/conf/${key}`);
export const GetAppDefaultConfig = (key: string, name: string) => {
return http.post<string>(`apps/installed/conf`, { type: key, name: name });
};
export const GetAppInstallParams = (id: number) => {

View File

@ -2,7 +2,7 @@
<div v-loading="loading">
<LayoutContent>
<template #title>
<back-button name="MySQL" :header="'MySQL ' + $t('commons.button.set')" />
<back-button name="MySQL" :header="$t('commons.button.set')" />
</template>
<template #toolbar>
@ -177,8 +177,8 @@ const jumpToSlowlog = async () => {
const onSubmitChangePort = async () => {
let params = {
key: 'mysql',
name: mysqlName.value,
key: props.type,
name: props.database,
port: baseInfo.port,
};
loading.value = true;
@ -216,10 +216,15 @@ function callback(error: any) {
const getDefaultConfig = async () => {
loading.value = true;
const res = await GetAppDefaultConfig('mysql');
mysqlConf.value = res.data;
useOld.value = true;
loading.value = false;
await GetAppDefaultConfig(props.type, props.database)
.then((res) => {
mysqlConf.value = res.data;
useOld.value = true;
loading.value = false;
})
.catch(() => {
loading.value = false;
});
};
const onSubmitChangeConf = async () => {

View File

@ -292,10 +292,15 @@ const submtiForm = async () => {
const getDefaultConfig = async () => {
loading.value = true;
const res = await GetAppDefaultConfig('redis');
redisConf.value = res.data;
useOld.value = true;
loading.value = false;
await GetAppDefaultConfig('redis', '')
.then((res) => {
redisConf.value = res.data;
useOld.value = true;
loading.value = false;
})
.catch(() => {
loading.value = false;
});
};
const onSaveFile = async () => {
@ -319,7 +324,7 @@ const submtiFile = async () => {
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
})
.catch(() => {
loading.value = true;
loading.value = false;
});
};

View File

@ -78,7 +78,7 @@ const getNginx = async () => {
const getDefaultConfig = async () => {
loading.value = true;
try {
const res = await GetAppDefaultConfig('openresty');
const res = await GetAppDefaultConfig('openresty', '');
content.value = res.data;
useOld.value = true;
} catch (error) {}