fix: fail to create config #724 #720

This commit is contained in:
Jacky 2024-11-15 19:30:03 +08:00
parent 56e82d9c5a
commit a2c0e804a4
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
5 changed files with 19 additions and 25 deletions

View file

@ -18,7 +18,7 @@ import (
func AddConfig(c *gin.Context) {
var json struct {
Name string `json:"name" binding:"required"`
NewFilepath string `json:"new_filepath" binding:"required"`
BaseDir string `json:"base_dir"`
Content string `json:"content"`
Overwrite bool `json:"overwrite"`
SyncNodeIds []uint64 `json:"sync_node_ids"`
@ -30,10 +30,11 @@ func AddConfig(c *gin.Context) {
name := json.Name
content := json.Content
path := json.NewFilepath
dir := nginx.GetConfPath(json.BaseDir)
path := filepath.Join(dir, json.Name)
if !helper.IsUnderDirectory(path, nginx.GetConfPath()) {
c.JSON(http.StatusForbidden, gin.H{
"message": "new filepath is not under the nginx conf path",
"message": "filepath is not under the nginx conf path",
})
return
}
@ -46,7 +47,6 @@ func AddConfig(c *gin.Context) {
}
// check if the dir exists, if not, use mkdirAll to create the dir
dir := filepath.Dir(path)
if !helper.FileExists(dir) {
err := os.MkdirAll(dir, 0755)
if err != nil {
@ -89,7 +89,7 @@ func AddConfig(c *gin.Context) {
return
}
err = config.SyncToRemoteServer(cfg, json.NewFilepath)
err = config.SyncToRemoteServer(cfg, path)
if err != nil {
api.ErrHandler(c, err)
return