From c485fe2bd51639cb5c164fb07aa7810ffecc3131 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 6 Sep 2023 21:22:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#2208)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/app_install.go | 12 ++++++------ backend/app/repo/app_install.go | 1 + backend/app/service/app_install.go | 12 ++++++------ backend/constant/app.go | 1 + backend/router/ro_app.go | 2 +- cmd/server/docs/docs.go | 18 ++++++++++++------ cmd/server/docs/swagger.json | 18 ++++++++++++------ cmd/server/docs/swagger.yaml | 14 +++++++++----- frontend/src/api/modules/app.ts | 4 ++-- .../views/database/mysql/setting/index.vue | 19 ++++++++++++------- .../views/database/redis/setting/index.vue | 15 ++++++++++----- .../website/website/nginx/source/index.vue | 2 +- 12 files changed, 73 insertions(+), 45 deletions(-) diff --git a/backend/app/api/v1/app_install.go b/backend/app/api/v1/app_install.go index 6675d801f..ccae9bdaa 100644 --- a/backend/app/api/v1/app_install.go +++ b/backend/app/api/v1/app_install.go @@ -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 diff --git a/backend/app/repo/app_install.go b/backend/app/repo/app_install.go index 03465fc2d..bc4067c99 100644 --- a/backend/app/repo/app_install.go +++ b/backend/app/repo/app_install.go @@ -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 } diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index 6473aea0f..668ec69ad 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -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 { diff --git a/backend/constant/app.go b/backend/constant/app.go index c38368e54..5df212bbc 100644 --- a/backend/constant/app.go +++ b/backend/constant/app.go @@ -21,6 +21,7 @@ const ( AppOpenresty = "openresty" AppMysql = "mysql" + AppMariaDB = "mariadb" AppRedis = "redis" AppResourceLocal = "local" diff --git a/backend/router/ro_app.go b/backend/router/ro_app.go index 4aba7d68d..be2d0c3e6 100644 --- a/backend/router/ro_app.go +++ b/backend/router/ro_app.go @@ -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) diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 8a4eda2ba..74789bb0f 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -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" }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index abc8a81fa..bb181144a 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -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" }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index 366207200..4560d7a50 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -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 diff --git a/frontend/src/api/modules/app.ts b/frontend/src/api/modules/app.ts index 2de2fc784..d1ad48f4a 100644 --- a/frontend/src/api/modules/app.ts +++ b/frontend/src/api/modules/app.ts @@ -82,8 +82,8 @@ export const GetAppUpdateVersions = (id: number) => { return http.get(`apps/installed/${id}/versions`); }; -export const GetAppDefaultConfig = (key: string) => { - return http.get(`apps/installed/conf/${key}`); +export const GetAppDefaultConfig = (key: string, name: string) => { + return http.post(`apps/installed/conf`, { type: key, name: name }); }; export const GetAppInstallParams = (id: number) => { diff --git a/frontend/src/views/database/mysql/setting/index.vue b/frontend/src/views/database/mysql/setting/index.vue index 515de8b63..6e2918944 100644 --- a/frontend/src/views/database/mysql/setting/index.vue +++ b/frontend/src/views/database/mysql/setting/index.vue @@ -2,7 +2,7 @@