update box api
This commit is contained in:
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,3 +1,12 @@
|
|||||||
config.json
|
config.json
|
||||||
backup
|
backup
|
||||||
backup.json
|
backup.json
|
||||||
|
tmp/server_test.go
|
||||||
|
tmp/server.go
|
||||||
|
tmp/static/script.js
|
||||||
|
tmp/static/style.css
|
||||||
|
tmp/templates/app_form.html
|
||||||
|
tmp/templates/apps.html
|
||||||
|
tmp/templates/box.html
|
||||||
|
tmp/templates/email.html
|
||||||
|
tmp/templates/login.html
|
||||||
|
|||||||
4
admin.go
4
admin.go
@@ -73,6 +73,10 @@ func (a *AdminConfig) Run() {
|
|||||||
r.GET("/app/:app/source/add/*src", ApiAppSourceAdd)
|
r.GET("/app/:app/source/add/*src", ApiAppSourceAdd)
|
||||||
r.GET("/app/:app/source/del/*src", ApiAppSourceDel)
|
r.GET("/app/:app/source/del/*src", ApiAppSourceDel)
|
||||||
|
|
||||||
|
r.GET("/box/list", ApiBoxList)
|
||||||
|
r.GET("/box/add/:box", ApiBoxAdd)
|
||||||
|
r.GET("/box/del/:box", ApiBoxDel)
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: a.Addr,
|
Addr: a.Addr,
|
||||||
Handler: r,
|
Handler: r,
|
||||||
|
|||||||
136
api.go
136
api.go
@@ -634,3 +634,139 @@ func ApiAppSourceDel(c *gin.Context) {
|
|||||||
"message": "done",
|
"message": "done",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ApiBoxList(c *gin.Context) {
|
||||||
|
log.WithFields(log.Fields{}).Debugf("starting")
|
||||||
|
log.WithFields(log.Fields{}).Debugf("done")
|
||||||
|
|
||||||
|
list := make([]string, 0)
|
||||||
|
|
||||||
|
CfgLock()
|
||||||
|
defer CfgUnlock()
|
||||||
|
|
||||||
|
for name, _ := range cfg.Box {
|
||||||
|
list = append(list, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
slices.Sort(list)
|
||||||
|
|
||||||
|
b, err := json.Marshal(list)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": fmt.Sprint(err),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Data(http.StatusOK, "application/json", pretty.PrettyOptions(b, &pretty.Options{Indent: " "}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func ApiBoxAdd(c *gin.Context) {
|
||||||
|
log.WithFields(log.Fields{"box": c.Param("box")}).Debugf("starting")
|
||||||
|
log.WithFields(log.Fields{"box": c.Param("box")}).Debugf("done")
|
||||||
|
|
||||||
|
name := c.Param("box")
|
||||||
|
|
||||||
|
CfgLock()
|
||||||
|
defer CfgUnlock()
|
||||||
|
|
||||||
|
if _, ok := cfg.Box[name]; ok {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "box already exist",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
box := &BoxConfig{}
|
||||||
|
cfg.Box[name] = box
|
||||||
|
|
||||||
|
err := cfg.Save(false)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": fmt.Sprint(err),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"message": "done",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func ApiBoxDel(c *gin.Context) {
|
||||||
|
log.WithFields(log.Fields{"box": c.Param("box")}).Debugf("starting")
|
||||||
|
log.WithFields(log.Fields{"box": c.Param("box")}).Debugf("done")
|
||||||
|
|
||||||
|
name := c.Param("box")
|
||||||
|
|
||||||
|
CfgLock()
|
||||||
|
defer CfgUnlock()
|
||||||
|
|
||||||
|
if _, ok := cfg.Box[name]; !ok {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "no box found",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, app := range cfg.Apps {
|
||||||
|
for _, src := range app.Sources {
|
||||||
|
a := Addr(src)
|
||||||
|
if a.Box() == name {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": fmt.Sprintf("box used in %s", app.Name),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, dst := range app.Destinations {
|
||||||
|
a := Addr(dst)
|
||||||
|
if a.Box() == name {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": fmt.Sprintf("box used in %s", app.Name),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, bfr := range app.Before {
|
||||||
|
a := Addr(bfr)
|
||||||
|
if a.Box() == name {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": fmt.Sprintf("box used in %s", app.Name),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, atr := range app.After {
|
||||||
|
a := Addr(atr)
|
||||||
|
if a.Box() == name {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": fmt.Sprintf("box used in %s", app.Name),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(cfg.Box, name)
|
||||||
|
delete(cfg.box, name)
|
||||||
|
|
||||||
|
err := cfg.Save(false)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": fmt.Sprint(err),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"message": "done",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||||
package main
|
package main
|
||||||
var githash = "54d8576"
|
var githash = "3aa0a85"
|
||||||
var branch = "master"
|
var branch = "master"
|
||||||
var buildstamp = "2025-12-28_21:17:45"
|
var buildstamp = "2026-01-10_10:33:26"
|
||||||
var commits = "129"
|
var commits = "130"
|
||||||
var version = "54d8576-b129 - 2025-12-28_21:17:45"
|
var version = "3aa0a85-b130 - 2026-01-10_10:33:26"
|
||||||
|
|||||||
Reference in New Issue
Block a user