feat: config history

This commit is contained in:
Jacky 2025-04-06 10:40:49 +08:00
parent 771859d3b8
commit 57b8dfd2f9
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
15 changed files with 823 additions and 75 deletions

13
api/config/history.go Normal file
View file

@ -0,0 +1,13 @@
package config
import (
"github.com/0xJacky/Nginx-UI/model"
"github.com/gin-gonic/gin"
"github.com/uozi-tech/cosy"
)
func GetConfigHistory(c *gin.Context) {
cosy.Core[model.ConfigBackup](c).
SetEqual("filepath").
PagingList()
}

View file

@ -47,6 +47,12 @@ func EditConfig(c *gin.Context) {
return
}
err = config.CheckAndCreateHistory(absPath, content)
if err != nil {
cosy.ErrHandler(c, err)
return
}
if content != "" && content != string(origContent) {
err = os.WriteFile(absPath, []byte(content), 0644)
if err != nil {

View file

@ -18,4 +18,6 @@ func InitRouter(r *gin.RouterGroup) {
o.POST("config_mkdir", Mkdir)
o.POST("config_rename", Rename)
}
r.GET("config_histories", GetConfigHistory)
}