mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
fix(config): [sync] missing base dir #778
This commit is contained in:
parent
c4f1e01e26
commit
564431cefe
5 changed files with 15 additions and 41 deletions
|
@ -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
|
||||
|
|
|
@ -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 @@
|
|||
{"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,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>
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue