mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-02-07 17:10:07 +08:00
fix: 解决获取默认配置失败的问题 (#2208)
This commit is contained in:
parent
add4fab794
commit
c485fe2bd5
@ -262,17 +262,17 @@ func (b *BaseApi) ChangeAppPort(c *gin.Context) {
|
|||||||
// @Summary Search default config by key
|
// @Summary Search default config by key
|
||||||
// @Description 通过 key 获取应用默认配置
|
// @Description 通过 key 获取应用默认配置
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Param key path string true "request"
|
// @Param request body dto.OperationWithNameAndType true "request"
|
||||||
// @Success 200 {string} content
|
// @Success 200 {string} content
|
||||||
// @Security ApiKeyAuth
|
// @Security ApiKeyAuth
|
||||||
// @Router /apps/installed/conf/:key [get]
|
// @Router /apps/installed/conf [post]
|
||||||
func (b *BaseApi) GetDefaultConfig(c *gin.Context) {
|
func (b *BaseApi) GetDefaultConfig(c *gin.Context) {
|
||||||
key := c.Param("key")
|
var req dto.OperationWithNameAndType
|
||||||
if key == "" {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content, err := appInstallService.GetDefaultConfigByKey(key)
|
content, err := appInstallService.GetDefaultConfigByKey(req.Type, req.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||||
return
|
return
|
||||||
|
@ -219,5 +219,6 @@ func (a *AppInstallRepo) LoadBaseInfo(key string, name string) (*RootInfo, error
|
|||||||
info.Env = appInstall.Env
|
info.Env = appInstall.Env
|
||||||
info.Param = appInstall.Param
|
info.Param = appInstall.Param
|
||||||
info.Version = appInstall.Version
|
info.Version = appInstall.Version
|
||||||
|
info.Key = app.Key
|
||||||
return &info, nil
|
return &info, nil
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ type IAppInstallService interface {
|
|||||||
GetUpdateVersions(installId uint) ([]dto.AppVersion, error)
|
GetUpdateVersions(installId uint) ([]dto.AppVersion, error)
|
||||||
GetParams(id uint) (*response.AppConfig, error)
|
GetParams(id uint) (*response.AppConfig, error)
|
||||||
ChangeAppPort(req request.PortUpdate) error
|
ChangeAppPort(req request.PortUpdate) error
|
||||||
GetDefaultConfigByKey(key string) (string, error)
|
GetDefaultConfigByKey(key, name string) (string, error)
|
||||||
DeleteCheck(installId uint) ([]dto.AppResource, error)
|
DeleteCheck(installId uint) ([]dto.AppResource, error)
|
||||||
|
|
||||||
GetInstallList() ([]dto.AppInstallInfo, error)
|
GetInstallList() ([]dto.AppInstallInfo, error)
|
||||||
@ -572,22 +572,22 @@ func (a *AppInstallService) DeleteCheck(installId uint) ([]dto.AppResource, erro
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AppInstallService) GetDefaultConfigByKey(key string) (string, error) {
|
func (a *AppInstallService) GetDefaultConfigByKey(key, name string) (string, error) {
|
||||||
appInstall, err := getAppInstallByKey(key)
|
baseInfo, err := appInstallRepo.LoadBaseInfo(key, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
fileOp := files.NewFileOp()
|
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) {
|
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) {
|
if !fileOp.Stat(filePath) {
|
||||||
return "", buserr.New(constant.ErrPathNotFound)
|
return "", buserr.New(constant.ErrPathNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
if key == constant.AppMysql {
|
if key == constant.AppMysql || key == constant.AppMariaDB {
|
||||||
filePath = path.Join(filePath, "my.cnf")
|
filePath = path.Join(filePath, "my.cnf")
|
||||||
}
|
}
|
||||||
if key == constant.AppRedis {
|
if key == constant.AppRedis {
|
||||||
|
@ -21,6 +21,7 @@ const (
|
|||||||
|
|
||||||
AppOpenresty = "openresty"
|
AppOpenresty = "openresty"
|
||||||
AppMysql = "mysql"
|
AppMysql = "mysql"
|
||||||
|
AppMariaDB = "mariadb"
|
||||||
AppRedis = "redis"
|
AppRedis = "redis"
|
||||||
|
|
||||||
AppResourceLocal = "local"
|
AppResourceLocal = "local"
|
||||||
|
@ -34,7 +34,7 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) {
|
|||||||
appRouter.POST("/installed/sync", baseApi.SyncInstalled)
|
appRouter.POST("/installed/sync", baseApi.SyncInstalled)
|
||||||
appRouter.POST("/installed/port/change", baseApi.ChangeAppPort)
|
appRouter.POST("/installed/port/change", baseApi.ChangeAppPort)
|
||||||
appRouter.GET("/services/:key", baseApi.GetServices)
|
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.GET("/installed/params/:appInstallId", baseApi.GetParams)
|
||||||
appRouter.POST("/installed/params/update", baseApi.UpdateInstalled)
|
appRouter.POST("/installed/params/update", baseApi.UpdateInstalled)
|
||||||
appRouter.POST("/installed/ignore", baseApi.IgnoreUpgrade)
|
appRouter.POST("/installed/ignore", baseApi.IgnoreUpgrade)
|
||||||
|
@ -315,8 +315,8 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/apps/installed/conf/:key": {
|
"/apps/installed/conf": {
|
||||||
"get": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"ApiKeyAuth": []
|
"ApiKeyAuth": []
|
||||||
@ -332,11 +332,13 @@ const docTemplate = `{
|
|||||||
"summary": "Search default config by key",
|
"summary": "Search default config by key",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
|
||||||
"description": "request",
|
"description": "request",
|
||||||
"name": "key",
|
"name": "request",
|
||||||
"in": "path",
|
"in": "body",
|
||||||
"required": true
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/dto.OperationWithNameAndType"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
@ -12904,6 +12906,7 @@ const docTemplate = `{
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"password",
|
"password",
|
||||||
|
"type",
|
||||||
"username",
|
"username",
|
||||||
"version"
|
"version"
|
||||||
],
|
],
|
||||||
@ -12923,6 +12926,9 @@ const docTemplate = `{
|
|||||||
"port": {
|
"port": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"username": {
|
"username": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
@ -308,8 +308,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/apps/installed/conf/:key": {
|
"/apps/installed/conf": {
|
||||||
"get": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"ApiKeyAuth": []
|
"ApiKeyAuth": []
|
||||||
@ -325,11 +325,13 @@
|
|||||||
"summary": "Search default config by key",
|
"summary": "Search default config by key",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
|
||||||
"description": "request",
|
"description": "request",
|
||||||
"name": "key",
|
"name": "request",
|
||||||
"in": "path",
|
"in": "body",
|
||||||
"required": true
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/dto.OperationWithNameAndType"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
@ -12897,6 +12899,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"password",
|
"password",
|
||||||
|
"type",
|
||||||
"username",
|
"username",
|
||||||
"version"
|
"version"
|
||||||
],
|
],
|
||||||
@ -12916,6 +12919,9 @@
|
|||||||
"port": {
|
"port": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"username": {
|
"username": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
@ -821,12 +821,15 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
port:
|
port:
|
||||||
type: integer
|
type: integer
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
username:
|
username:
|
||||||
type: string
|
type: string
|
||||||
version:
|
version:
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
- password
|
- password
|
||||||
|
- type
|
||||||
- username
|
- username
|
||||||
- version
|
- version
|
||||||
type: object
|
type: object
|
||||||
@ -4223,17 +4226,18 @@ paths:
|
|||||||
summary: Check app installed
|
summary: Check app installed
|
||||||
tags:
|
tags:
|
||||||
- App
|
- App
|
||||||
/apps/installed/conf/:key:
|
/apps/installed/conf:
|
||||||
get:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: 通过 key 获取应用默认配置
|
description: 通过 key 获取应用默认配置
|
||||||
parameters:
|
parameters:
|
||||||
- description: request
|
- description: request
|
||||||
in: path
|
in: body
|
||||||
name: key
|
name: request
|
||||||
required: true
|
required: true
|
||||||
type: string
|
schema:
|
||||||
|
$ref: '#/definitions/dto.OperationWithNameAndType'
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
|
@ -82,8 +82,8 @@ export const GetAppUpdateVersions = (id: number) => {
|
|||||||
return http.get<any>(`apps/installed/${id}/versions`);
|
return http.get<any>(`apps/installed/${id}/versions`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GetAppDefaultConfig = (key: string) => {
|
export const GetAppDefaultConfig = (key: string, name: string) => {
|
||||||
return http.get<string>(`apps/installed/conf/${key}`);
|
return http.post<string>(`apps/installed/conf`, { type: key, name: name });
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GetAppInstallParams = (id: number) => {
|
export const GetAppInstallParams = (id: number) => {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<div v-loading="loading">
|
<div v-loading="loading">
|
||||||
<LayoutContent>
|
<LayoutContent>
|
||||||
<template #title>
|
<template #title>
|
||||||
<back-button name="MySQL" :header="'MySQL ' + $t('commons.button.set')" />
|
<back-button name="MySQL" :header="$t('commons.button.set')" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #toolbar>
|
<template #toolbar>
|
||||||
@ -177,8 +177,8 @@ const jumpToSlowlog = async () => {
|
|||||||
|
|
||||||
const onSubmitChangePort = async () => {
|
const onSubmitChangePort = async () => {
|
||||||
let params = {
|
let params = {
|
||||||
key: 'mysql',
|
key: props.type,
|
||||||
name: mysqlName.value,
|
name: props.database,
|
||||||
port: baseInfo.port,
|
port: baseInfo.port,
|
||||||
};
|
};
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
@ -216,10 +216,15 @@ function callback(error: any) {
|
|||||||
|
|
||||||
const getDefaultConfig = async () => {
|
const getDefaultConfig = async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const res = await GetAppDefaultConfig('mysql');
|
await GetAppDefaultConfig(props.type, props.database)
|
||||||
|
.then((res) => {
|
||||||
mysqlConf.value = res.data;
|
mysqlConf.value = res.data;
|
||||||
useOld.value = true;
|
useOld.value = true;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmitChangeConf = async () => {
|
const onSubmitChangeConf = async () => {
|
||||||
|
@ -292,10 +292,15 @@ const submtiForm = async () => {
|
|||||||
|
|
||||||
const getDefaultConfig = async () => {
|
const getDefaultConfig = async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const res = await GetAppDefaultConfig('redis');
|
await GetAppDefaultConfig('redis', '')
|
||||||
|
.then((res) => {
|
||||||
redisConf.value = res.data;
|
redisConf.value = res.data;
|
||||||
useOld.value = true;
|
useOld.value = true;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSaveFile = async () => {
|
const onSaveFile = async () => {
|
||||||
@ -319,7 +324,7 @@ const submtiFile = async () => {
|
|||||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
loading.value = true;
|
loading.value = false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ const getNginx = async () => {
|
|||||||
const getDefaultConfig = async () => {
|
const getDefaultConfig = async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
const res = await GetAppDefaultConfig('openresty');
|
const res = await GetAppDefaultConfig('openresty', '');
|
||||||
content.value = res.data;
|
content.value = res.data;
|
||||||
useOld.value = true;
|
useOld.value = true;
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user