refactor: refactor app and api

This commit is contained in:
0xJacky 2023-11-29 00:08:44 +08:00
parent 5ab50b8a93
commit 287ef7527d
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
157 changed files with 8116 additions and 3587 deletions

51
api/config/modify.go Normal file
View file

@ -0,0 +1,51 @@
package config
import (
"github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/gin-gonic/gin"
"net/http"
"os"
)
type EditConfigJson struct {
Content string `json:"content" binding:"required"`
}
func EditConfig(c *gin.Context) {
name := c.Param("name")
var request EditConfigJson
err := c.BindJSON(&request)
if err != nil {
api.ErrHandler(c, err)
return
}
path := nginx.GetConfPath("/", name)
content := request.Content
origContent, err := os.ReadFile(path)
if err != nil {
api.ErrHandler(c, err)
return
}
if content != "" && content != string(origContent) {
// model.CreateBackup(path)
err = os.WriteFile(path, []byte(content), 0644)
if err != nil {
api.ErrHandler(c, err)
return
}
}
output := nginx.Reload()
if nginx.GetLogLevel(output) >= nginx.Warn {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
return
}
GetConfig(c)
}