added folders config update
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2022-02-25 12:12:57 +01:00
parent de8717dc99
commit 52e767b941
2 changed files with 26 additions and 0 deletions

View File

@ -69,6 +69,23 @@ func GetFolders(cfg config.Config) (res []Folder, err error) {
return
}
// InsertOrUpdateFolders ...
func InsertOrUpdateFolders(cfg config.Config, folders []Folder) (res string, err error) {
var w = Cfg{Key: "folders"}
if exists, _ := cfg.Db.Get(&w); exists {
resbytes, err := json.Marshal(folders)
if err != nil {
return "", err
}
w.Value = string(resbytes)
_, err = cfg.Db.ID(w.ID).Update(&w)
if err != nil {
return "", err
}
}
return
}
type Trustlist struct {
IP string `json:"ip"`
}

View File

@ -111,6 +111,15 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
folders, err := models.GetFolders(*cfg)
return Result(c, err, folders)
})
e.POST("/ips/folders", func(c echo.Context) (err error) {
var folders []models.Folder
err = c.Bind(&folders)
if err != nil {
return Result(c, err, "Unable to parse JSON")
}
_, err = models.InsertOrUpdateFolders(*cfg, folders)
return Result(c, err, folders)
})
e.Logger.Fatal(
e.Start(