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) {
|
func AddConfig(c *gin.Context) {
|
||||||
var json struct {
|
var json struct {
|
||||||
Name string `json:"name" binding:"required"`
|
config.SyncConfigPayload
|
||||||
BaseDir string `json:"base_dir"`
|
|
||||||
Content string `json:"content"`
|
|
||||||
Overwrite bool `json:"overwrite"`
|
|
||||||
SyncNodeIds []uint64 `json:"sync_node_ids"`
|
SyncNodeIds []uint64 `json:"sync_node_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +87,7 @@ func AddConfig(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = config.SyncToRemoteServer(cfg, path)
|
err = config.SyncToRemoteServer(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.ErrHandler(c, err)
|
api.ErrHandler(c, err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -77,7 +77,7 @@ func EditConfig(c *gin.Context) {
|
||||||
cfg.SyncOverwrite = json.SyncOverwrite
|
cfg.SyncOverwrite = json.SyncOverwrite
|
||||||
|
|
||||||
g := query.ChatGPTLog
|
g := query.ChatGPTLog
|
||||||
err = config.SyncToRemoteServer(cfg, absPath)
|
err = config.SyncToRemoteServer(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.ErrHandler(c, err)
|
api.ErrHandler(c, err)
|
||||||
return
|
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">
|
<script setup lang="ts">
|
||||||
|
import GithubButton from '@0xjacky/vue-github-button'
|
||||||
import logo from '@/assets/img/logo.png'
|
import logo from '@/assets/img/logo.png'
|
||||||
import ver from '@/version.json'
|
import ver from '@/version.json'
|
||||||
import GithubButton from '@0xjacky/vue-github-button'
|
|
||||||
|
|
||||||
const thisYear = new Date().getFullYear()
|
const thisYear = new Date().getFullYear()
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -22,14 +22,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type SyncConfigPayload struct {
|
type SyncConfigPayload struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name" binding:"required"`
|
||||||
Filepath string `json:"filepath"`
|
BaseDir string `json:"base_dir"`
|
||||||
NewFilepath string `json:"new_filepath"`
|
Content string `json:"content"`
|
||||||
Content string `json:"content"`
|
Overwrite bool `json:"overwrite"`
|
||||||
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 {
|
if c.Filepath == "" || len(c.SyncNodeIds) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -40,26 +39,16 @@ func SyncToRemoteServer(c *model.Config, newFilepath string) (err error) {
|
||||||
c.Filepath, nginxConfPath)
|
c.Filepath, nginxConfPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if newFilepath != "" && !helper.IsUnderDirectory(newFilepath, nginxConfPath) {
|
configBytes, err := os.ReadFile(c.Filepath)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := &SyncConfigPayload{
|
payload := &SyncConfigPayload{
|
||||||
Name: c.Name,
|
Name: c.Name,
|
||||||
Filepath: c.Filepath,
|
BaseDir: strings.ReplaceAll(filepath.Dir(c.Filepath), nginx.GetConfPath(), ""),
|
||||||
NewFilepath: newFilepath,
|
Content: string(configBytes),
|
||||||
Content: string(configBytes),
|
Overwrite: c.SyncOverwrite,
|
||||||
Overwrite: c.SyncOverwrite,
|
|
||||||
}
|
}
|
||||||
payloadBytes, err := json.Marshal(payload)
|
payloadBytes, err := json.Marshal(payload)
|
||||||
if err != nil {
|
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))
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue