From c460d9fd7d292e84fafbb5d651c2bff8d45dab20 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Sun, 4 May 2025 21:20:06 +0800 Subject: [PATCH] fix: Modify the script and upload the file name (#8538) --- core/app/api/v2/script_library.go | 12 ++++++++++-- frontend/src/views/cronjob/library/index.vue | 4 ++-- frontend/src/views/cronjob/library/operate/index.vue | 9 +++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/core/app/api/v2/script_library.go b/core/app/api/v2/script_library.go index 93d39751d..3ef924913 100644 --- a/core/app/api/v2/script_library.go +++ b/core/app/api/v2/script_library.go @@ -1,9 +1,11 @@ package v2 import ( + "encoding/json" "fmt" "path" "strconv" + "strings" "github.com/1Panel-dev/1Panel/core/app/api/v2/helper" "github.com/1Panel-dev/1Panel/core/app/dto" @@ -13,7 +15,6 @@ import ( "github.com/1Panel-dev/1Panel/core/utils/terminal" "github.com/1Panel-dev/1Panel/core/utils/xpack" "github.com/gin-gonic/gin" - "github.com/google/uuid" "github.com/pkg/errors" ) @@ -182,7 +183,14 @@ func (b *BaseApi) RunScript(c *gin.Context) { } fileDir := path.Join(installDir, "1panel/tmp/script") - fileName := path.Join(fileDir, uuid.NewString()) + fileName := "" + var translations = make(map[string]string) + _ = json.Unmarshal([]byte(scriptItem.Name), &translations) + if name, ok := translations["en"]; ok { + fileName = path.Join(fileDir, strings.ReplaceAll(name, " ", "_")) + } else { + fileName = path.Join(fileDir, strings.ReplaceAll(scriptItem.Name, " ", "_")) + } initCmd := fmt.Sprintf("mkdir -p %s && cat > %s <<'MYMARKER'\n%s\nMYMARKER\n bash %s", fileDir, fileName, scriptItem.Script, fileName) client, err := ssh.NewClient(*connInfo) if wshandleError(wsConn, errors.WithMessage(err, "failed to set up the connection. Please check the host information")) { diff --git a/frontend/src/views/cronjob/library/index.vue b/frontend/src/views/cronjob/library/index.vue index fa0125ce6..bd446f926 100644 --- a/frontend/src/views/cronjob/library/index.vue +++ b/frontend/src/views/cronjob/library/index.vue @@ -49,7 +49,7 @@