From 23996b25c30c639679cafdd82cb36a0f300fbdd2 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Mon, 12 Dec 2022 17:17:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=8A=B6=E6=80=81=E6=A0=8F=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=87=8D=E5=90=AF=20loading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/app_install.go | 58 +++++++++---------- backend/app/service/container_compose.go | 2 +- backend/app/service/database_redis.go | 29 ---------- backend/utils/terminal/ws_local_session.go | 11 +--- frontend/src/components/app-status/index.vue | 15 +++-- frontend/src/global/form-rules.ts | 2 +- frontend/src/lang/modules/en.ts | 2 +- frontend/src/lang/modules/zh.ts | 2 +- .../src/views/container/compose/index.vue | 7 ++- frontend/src/views/database/mysql/index.vue | 13 ++++- frontend/src/views/database/redis/index.vue | 24 ++++++-- .../redis/setting/persistence/index.vue | 51 ++++++++++++---- .../src/views/host/terminal/host/index.vue | 7 +-- frontend/src/views/website/website/index.vue | 6 +- 14 files changed, 125 insertions(+), 104 deletions(-) diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index 9dab46b5e..47f98e322 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -263,36 +263,7 @@ func (a AppInstallService) GetUpdateVersions(installId uint) ([]dto.AppVersion, } func (a AppInstallService) ChangeAppPort(req dto.PortUpdate) error { - var ( - files []string - newFiles []string - ) - - ComposeDir := fmt.Sprintf("%s/%s/%s", constant.AppInstallDir, req.Key, req.Name) ComposeFile := fmt.Sprintf("%s/%s/%s/docker-compose.yml", constant.AppInstallDir, req.Key, req.Name) - path := fmt.Sprintf("%s/.env", ComposeDir) - lineBytes, err := ioutil.ReadFile(path) - if err != nil { - return err - } else { - files = strings.Split(string(lineBytes), "\n") - } - for _, line := range files { - if strings.HasPrefix(line, "PANEL_APP_PORT_HTTP=") { - newFiles = append(newFiles, fmt.Sprintf("PANEL_APP_PORT_HTTP=%v", req.Port)) - } else { - newFiles = append(newFiles, line) - } - } - file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0666) - if err != nil { - return err - } - defer file.Close() - _, err = file.WriteString(strings.Join(newFiles, "\n")) - if err != nil { - return err - } updateInstallInfoInDB(req.Key, "port", strconv.FormatInt(req.Port, 10)) @@ -484,6 +455,34 @@ func updateInstallInfoInDB(appKey, param string, value interface{}) { if err != nil { return } + envPath := fmt.Sprintf("%s/%s/%s/.env", constant.AppInstallDir, appKey, appInstall.Name) + lineBytes, err := ioutil.ReadFile(envPath) + if err != nil { + return + } + envKey := "PANEL_DB_ROOT_PASSWORD=" + if param == "port" { + envKey = "PANEL_APP_PORT_HTTP=" + } + files := strings.Split(string(lineBytes), "\n") + var newFiles []string + for _, line := range files { + if strings.HasPrefix(line, envKey) { + newFiles = append(newFiles, fmt.Sprintf("%s%v", envKey, value)) + } else { + newFiles = append(newFiles, line) + } + } + file, err := os.OpenFile(envPath, os.O_WRONLY|os.O_TRUNC, 0666) + if err != nil { + return + } + defer file.Close() + _, err = file.WriteString(strings.Join(newFiles, "\n")) + if err != nil { + return + } + oldVal, newVal := "", "" if param == "password" { oldVal = fmt.Sprintf("\"PANEL_DB_ROOT_PASSWORD\":\"%v\"", appInstall.Password) @@ -492,6 +491,7 @@ func updateInstallInfoInDB(appKey, param string, value interface{}) { "param": strings.ReplaceAll(appInstall.Param, oldVal, newVal), "env": strings.ReplaceAll(appInstall.Env, oldVal, newVal), }, commonRepo.WithByID(appInstall.ID)) + } if param == "port" { oldVal = fmt.Sprintf("\"PANEL_APP_PORT_HTTP\":%v", appInstall.Port) diff --git a/backend/app/service/container_compose.go b/backend/app/service/container_compose.go index 49aa6d92a..e994b0c72 100644 --- a/backend/app/service/container_compose.go +++ b/backend/app/service/container_compose.go @@ -79,7 +79,7 @@ func (u *ContainerService) PageCompose(req dto.PageInfo) (int64, interface{}, er } for i := 0; i < len(composeCreatedByLocal); i++ { if composeCreatedByLocal[i].Name == name { - composeItem.CreatedBy = "local" + composeItem.CreatedBy = "1panel" composeCreatedByLocal = append(composeCreatedByLocal[:i], composeCreatedByLocal[i+1:]...) break } diff --git a/backend/app/service/database_redis.go b/backend/app/service/database_redis.go index b79924ffb..c9bde952e 100644 --- a/backend/app/service/database_redis.go +++ b/backend/app/service/database_redis.go @@ -63,40 +63,11 @@ func (u *RedisService) UpdateConf(req dto.RedisConfUpdate) error { } func (u *RedisService) ChangePassword(req dto.ChangeDBInfo) error { - var ( - files []string - newFiles []string - ) - redisInfo, err := appInstallRepo.LoadBaseInfoByKey("redis") if err != nil { return err } - ComposeDir := fmt.Sprintf("%s/redis/%s", constant.AppInstallDir, redisInfo.Name) ComposeFile := fmt.Sprintf("%s/redis/%s/docker-compose.yml", constant.AppInstallDir, redisInfo.Name) - path := fmt.Sprintf("%s/.env", ComposeDir) - lineBytes, err := ioutil.ReadFile(path) - if err != nil { - return err - } else { - files = strings.Split(string(lineBytes), "\n") - } - for _, line := range files { - if strings.HasPrefix(line, "PANEL_DB_ROOT_PASSWORD=") { - newFiles = append(newFiles, fmt.Sprintf("PANEL_DB_ROOT_PASSWORD=%v", req.Value)) - } else { - newFiles = append(newFiles, line) - } - } - file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0666) - if err != nil { - return err - } - defer file.Close() - _, err = file.WriteString(strings.Join(newFiles, "\n")) - if err != nil { - return err - } updateInstallInfoInDB("redis", "password", req.Value) updateInstallInfoInDB("redis-commander", "password", req.Value) diff --git a/backend/utils/terminal/ws_local_session.go b/backend/utils/terminal/ws_local_session.go index 92209c8dc..136658ebc 100644 --- a/backend/utils/terminal/ws_local_session.go +++ b/backend/utils/terminal/ws_local_session.go @@ -42,15 +42,8 @@ func (sws *LocalWsSession) handleSlaveEvent(exitCh chan bool) { case <-exitCh: return default: - n, err := sws.slave.Read(buffer) - if err != nil { - global.LOG.Errorf("read buffer from slave failed, err: %v", err) - } - - err = sws.masterWrite(buffer[:n]) - if err != nil { - global.LOG.Errorf("handle master read event failed, err: %v", err) - } + n, _ := sws.slave.Read(buffer) + _ = sws.masterWrite(buffer[:n]) } } } diff --git a/frontend/src/components/app-status/index.vue b/frontend/src/components/app-status/index.vue index f66565855..2749a94ab 100644 --- a/frontend/src/components/app-status/index.vue +++ b/frontend/src/components/app-status/index.vue @@ -1,7 +1,7 @@ - + + + -
+
- + @@ -193,6 +199,8 @@ import { App } from '@/api/interface/app'; import { GetAppPort } from '@/api/modules/app'; import router from '@/routers'; +const loading = ref(false); + const selects = ref([]); const mysqlName = ref(); const isOnSetting = ref(); @@ -353,6 +361,7 @@ const onDelete = async (row: Database.MysqlDBInfo) => { search(); } }; + const buttons = [ { label: i18n.global.t('database.changePassword'), diff --git a/frontend/src/views/database/redis/index.vue b/frontend/src/views/database/redis/index.vue index 4d962ff2c..ec48c34ff 100644 --- a/frontend/src/views/database/redis/index.vue +++ b/frontend/src/views/database/redis/index.vue @@ -1,15 +1,23 @@