mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
feat: config history
This commit is contained in:
parent
771859d3b8
commit
57b8dfd2f9
15 changed files with 823 additions and 75 deletions
|
@ -1,45 +1,8 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/uozi-tech/cosy/logger"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type ConfigBackup struct {
|
||||
Model
|
||||
Name string `json:"name"`
|
||||
FilePath string `json:"filepath"`
|
||||
FilePath string `json:"filepath" gorm:"column:filepath"`
|
||||
Content string `json:"content" gorm:"type:text"`
|
||||
}
|
||||
|
||||
type ConfigBackupListItem struct {
|
||||
Model
|
||||
Name string `json:"name"`
|
||||
FilePath string `json:"filepath"`
|
||||
}
|
||||
|
||||
func GetBackupList(path string) (configs []ConfigBackupListItem) {
|
||||
db.Model(&ConfigBackup{}).
|
||||
Where(&ConfigBackup{FilePath: path}).
|
||||
Find(&configs)
|
||||
return
|
||||
}
|
||||
|
||||
func GetBackup(id int) (config ConfigBackup) {
|
||||
db.First(&config, id)
|
||||
return
|
||||
}
|
||||
|
||||
func CreateBackup(path string) {
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
config := ConfigBackup{Name: filepath.Base(path), FilePath: path, Content: string(content)}
|
||||
result := db.Create(&config)
|
||||
if result.Error != nil {
|
||||
logger.Error(result.Error)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue