add app schedule api
This commit is contained in:
@@ -75,9 +75,13 @@ 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("/app/:app/dest/list", ApiAppDestList)
|
r.GET("/app/:app/dest/list", ApiAppDestinationList)
|
||||||
r.GET("/app/:app/dest/add/*dst", ApiAppDestAdd)
|
r.GET("/app/:app/dest/add/*dst", ApiAppDestinationAdd)
|
||||||
r.GET("/app/:app/dest/del/*dst", ApiAppDestDel)
|
r.GET("/app/:app/dest/del/*dst", ApiAppDestinationDel)
|
||||||
|
|
||||||
|
r.GET("/app/:app/schedule/list", ApiAppScheduleList)
|
||||||
|
r.GET("/app/:app/schedule/add/:schedule", ApiAppScheduleAdd)
|
||||||
|
r.GET("/app/:app/schedule/del/:schedule", ApiAppScheduleDel)
|
||||||
|
|
||||||
r.GET("/box/list", ApiBoxList)
|
r.GET("/box/list", ApiBoxList)
|
||||||
r.GET("/box/add/:box", ApiBoxAdd)
|
r.GET("/box/add/:box", ApiBoxAdd)
|
||||||
|
|||||||
@@ -693,7 +693,7 @@ func ApiAppSourceDel(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ApiAppDestList(c *gin.Context) {
|
func ApiAppDestinationList(c *gin.Context) {
|
||||||
log.WithFields(log.Fields{"app": c.Param("app")}).Debugf("starting")
|
log.WithFields(log.Fields{"app": c.Param("app")}).Debugf("starting")
|
||||||
log.WithFields(log.Fields{"app": c.Param("app")}).Debugf("done")
|
log.WithFields(log.Fields{"app": c.Param("app")}).Debugf("done")
|
||||||
|
|
||||||
@@ -730,7 +730,7 @@ func ApiAppDestList(c *gin.Context) {
|
|||||||
c.Data(http.StatusOK, "application/json", pretty.PrettyOptions(b, &pretty.Options{Indent: " "}))
|
c.Data(http.StatusOK, "application/json", pretty.PrettyOptions(b, &pretty.Options{Indent: " "}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ApiAppDestAdd(c *gin.Context) {
|
func ApiAppDestinationAdd(c *gin.Context) {
|
||||||
app := c.Param("app")
|
app := c.Param("app")
|
||||||
dst := c.Param("dst")
|
dst := c.Param("dst")
|
||||||
dst = dst[1:] // cut first char from wildcard match
|
dst = dst[1:] // cut first char from wildcard match
|
||||||
@@ -822,7 +822,7 @@ func ApiAppDestAdd(c *gin.Context) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ApiAppDestDel(c *gin.Context) {
|
func ApiAppDestinationDel(c *gin.Context) {
|
||||||
app := c.Param("app")
|
app := c.Param("app")
|
||||||
dst := c.Param("dst")
|
dst := c.Param("dst")
|
||||||
dst = dst[1:] // cut first char from wildcard match
|
dst = dst[1:] // cut first char from wildcard match
|
||||||
@@ -893,6 +893,179 @@ func ApiAppDestDel(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ApiAppScheduleList(c *gin.Context) {
|
||||||
|
log.WithFields(log.Fields{"app": c.Param("app")}).Debugf("starting")
|
||||||
|
log.WithFields(log.Fields{"app": c.Param("app")}).Debugf("done")
|
||||||
|
|
||||||
|
name := c.Param("app")
|
||||||
|
found := false
|
||||||
|
app := &AppConfig{}
|
||||||
|
|
||||||
|
CfgLock()
|
||||||
|
defer CfgUnlock()
|
||||||
|
|
||||||
|
for _, a := range cfg.Apps {
|
||||||
|
if a.Name == name {
|
||||||
|
found = true
|
||||||
|
app = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "app does not exist",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := json.Marshal(app.Schedule)
|
||||||
|
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 ApiAppScheduleAdd(c *gin.Context) {
|
||||||
|
app := c.Param("app")
|
||||||
|
schedule := c.Param("schedule")
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{"app": app, "schedule": schedule}).Debugf("starting")
|
||||||
|
log.WithFields(log.Fields{"app": app, "schedule": schedule}).Debugf("done")
|
||||||
|
|
||||||
|
found := false
|
||||||
|
ac := &AppConfig{}
|
||||||
|
|
||||||
|
CfgLock()
|
||||||
|
defer CfgUnlock()
|
||||||
|
|
||||||
|
for _, a := range cfg.Apps {
|
||||||
|
if a.Name == app {
|
||||||
|
found = true
|
||||||
|
ac = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "app does not exist",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if slices.Contains(ac.Schedule, schedule) {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "schedule already exists",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ac.Schedule = append(ac.Schedule, schedule)
|
||||||
|
|
||||||
|
if ac.Active {
|
||||||
|
a, err := cfg.NewApp(ac.Name, ac.Sources, ac.Destinations, ac.Schedule, ac.Before, ac.After)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": fmt.Sprint(err),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.apps[a.name] = a
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ApiAppScheduleDel(c *gin.Context) {
|
||||||
|
app := c.Param("app")
|
||||||
|
schedule := c.Param("schedule")
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{"app": app, "schedule": schedule}).Debugf("starting")
|
||||||
|
log.WithFields(log.Fields{"app": app, "schedule": schedule}).Debugf("done")
|
||||||
|
|
||||||
|
found := false
|
||||||
|
ac := &AppConfig{}
|
||||||
|
|
||||||
|
CfgLock()
|
||||||
|
defer CfgUnlock()
|
||||||
|
|
||||||
|
for _, a := range cfg.Apps {
|
||||||
|
if a.Name == app {
|
||||||
|
found = true
|
||||||
|
ac = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "app does not exist",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !slices.Contains(ac.Schedule, schedule) {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "schedule does not exist",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for id, s := range ac.Schedule {
|
||||||
|
if s == schedule {
|
||||||
|
ac.Schedule[id] = ac.Schedule[len(ac.Schedule)-1]
|
||||||
|
ac.Schedule = ac.Schedule[:len(ac.Schedule)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ac.Active {
|
||||||
|
a, err := cfg.NewApp(ac.Name, ac.Sources, ac.Destinations, ac.Schedule, ac.Before, ac.After)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": fmt.Sprint(err),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.apps[a.name] = a
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ApiBoxList(c *gin.Context) {
|
func ApiBoxList(c *gin.Context) {
|
||||||
log.WithFields(log.Fields{}).Debugf("starting")
|
log.WithFields(log.Fields{}).Debugf("starting")
|
||||||
log.WithFields(log.Fields{}).Debugf("done")
|
log.WithFields(log.Fields{}).Debugf("done")
|
||||||
|
|||||||
+4
-4
@@ -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 = "8fdaba6"
|
var githash = "fef11b6"
|
||||||
var branch = "master"
|
var branch = "master"
|
||||||
var buildstamp = "2026-06-17_20:16:26"
|
var buildstamp = "2026-06-17_20:54:42"
|
||||||
var commits = "135"
|
var commits = "137"
|
||||||
var version = "8fdaba6-b135 - 2026-06-17_20:16:26"
|
var version = "fef11b6-b137 - 2026-06-17_20:54:42"
|
||||||
|
|||||||
Reference in New Issue
Block a user