From 564431cefe504f8ac00dbb44efbafb789761c7a4 Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 14 Dec 2024 16:24:18 +0800 Subject: [PATCH] fix(config): [sync] missing base dir #778 --- api/config/add.go | 7 ++---- api/config/modify.go | 2 +- app/src/version.json | 2 +- app/src/views/system/About.vue | 2 +- internal/config/sync.go | 43 ++++++++-------------------------- 5 files changed, 15 insertions(+), 41 deletions(-) diff --git a/api/config/add.go b/api/config/add.go index 82769f38..614a0a11 100644 --- a/api/config/add.go +++ b/api/config/add.go @@ -18,10 +18,7 @@ import ( func AddConfig(c *gin.Context) { var json struct { - Name string `json:"name" binding:"required"` - BaseDir string `json:"base_dir"` - Content string `json:"content"` - Overwrite bool `json:"overwrite"` + config.SyncConfigPayload SyncNodeIds []uint64 `json:"sync_node_ids"` } @@ -90,7 +87,7 @@ func AddConfig(c *gin.Context) { return } - err = config.SyncToRemoteServer(cfg, path) + err = config.SyncToRemoteServer(cfg) if err != nil { api.ErrHandler(c, err) return diff --git a/api/config/modify.go b/api/config/modify.go index 9b8dd749..71fe078d 100644 --- a/api/config/modify.go +++ b/api/config/modify.go @@ -77,7 +77,7 @@ func EditConfig(c *gin.Context) { cfg.SyncOverwrite = json.SyncOverwrite g := query.ChatGPTLog - err = config.SyncToRemoteServer(cfg, absPath) + err = config.SyncToRemoteServer(cfg) if err != nil { api.ErrHandler(c, err) return diff --git a/app/src/version.json b/app/src/version.json index a0501450..7a24a1ad 100644 --- a/app/src/version.json +++ b/app/src/version.json @@ -1 +1 @@ -{"version":"2.0.0-beta.41","build_id":1,"total_build":372} \ No newline at end of file +{"version":"2.0.0-beta.41","build_id":2,"total_build":373} \ No newline at end of file diff --git a/app/src/views/system/About.vue b/app/src/views/system/About.vue index 3c63124c..17b03be4 100644 --- a/app/src/views/system/About.vue +++ b/app/src/views/system/About.vue @@ -1,7 +1,7 @@ diff --git a/internal/config/sync.go b/internal/config/sync.go index b675a9d7..4a99bb4a 100644 --- a/internal/config/sync.go +++ b/internal/config/sync.go @@ -22,14 +22,13 @@ import ( ) type SyncConfigPayload struct { - Name string `json:"name"` - Filepath string `json:"filepath"` - NewFilepath string `json:"new_filepath"` - Content string `json:"content"` - Overwrite bool `json:"overwrite"` + Name string `json:"name" binding:"required"` + BaseDir string `json:"base_dir"` + Content string `json:"content"` + Overwrite bool `json:"overwrite"` } -func SyncToRemoteServer(c *model.Config, newFilepath string) (err error) { +func SyncToRemoteServer(c *model.Config) (err error) { if c.Filepath == "" || len(c.SyncNodeIds) == 0 { return } @@ -40,26 +39,16 @@ func SyncToRemoteServer(c *model.Config, newFilepath string) (err error) { c.Filepath, nginxConfPath) } - if newFilepath != "" && !helper.IsUnderDirectory(newFilepath, nginxConfPath) { - return fmt.Errorf("config: %s is not under the nginx conf path: %s", - c.Filepath, nginxConfPath) - } - - currentPath := c.Filepath - if newFilepath != "" { - currentPath = newFilepath - } - configBytes, err := os.ReadFile(currentPath) + configBytes, err := os.ReadFile(c.Filepath) if err != nil { return } payload := &SyncConfigPayload{ - Name: c.Name, - Filepath: c.Filepath, - NewFilepath: newFilepath, - Content: string(configBytes), - Overwrite: c.SyncOverwrite, + Name: c.Name, + BaseDir: strings.ReplaceAll(filepath.Dir(c.Filepath), nginx.GetConfPath(), ""), + Content: string(configBytes), + Overwrite: c.SyncOverwrite, } payloadBytes, err := json.Marshal(payload) if err != nil { @@ -169,18 +158,6 @@ func (p *SyncConfigPayload) deploy(env *model.Environment, c *model.Config, payl notification.Success("Sync Config Success", string(notificationPayloadBytes)) - // handle rename - if p.NewFilepath == "" || p.Filepath == p.NewFilepath { - return - } - - payload := &RenameConfigPayload{ - Filepath: p.Filepath, - NewFilepath: p.NewFilepath, - } - - err = payload.rename(env) - return }