浏览代码

fix(config): [sync] missing base dir #778

Jacky 4 月之前
父节点
当前提交
564431cefe
共有 5 个文件被更改,包括 15 次插入41 次删除
  1. 2 5
      api/config/add.go
  2. 1 1
      api/config/modify.go
  3. 1 1
      app/src/version.json
  4. 1 1
      app/src/views/system/About.vue
  5. 10 33
      internal/config/sync.go

+ 2 - 5
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

+ 1 - 1
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

+ 1 - 1
app/src/version.json

@@ -1 +1 @@
-{"version":"2.0.0-beta.41","build_id":1,"total_build":372}
+{"version":"2.0.0-beta.41","build_id":2,"total_build":373}

+ 1 - 1
app/src/views/system/About.vue

@@ -1,7 +1,7 @@
 <script setup lang="ts">
+import GithubButton from '@0xjacky/vue-github-button'
 import logo from '@/assets/img/logo.png'
 import ver from '@/version.json'
-import GithubButton from '@0xjacky/vue-github-button'
 
 const thisYear = new Date().getFullYear()
 </script>

+ 10 - 33
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
 }