add destination api
This commit is contained in:
@@ -693,6 +693,206 @@ func ApiAppSourceDel(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ApiAppDestList(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.Destinations)
|
||||||
|
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 ApiAppDestAdd(c *gin.Context) {
|
||||||
|
app := c.Param("app")
|
||||||
|
dst := c.Param("dst")
|
||||||
|
dst = dst[1:] // cut first char from wildcard match
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{"app": app, "dst": dst}).Debugf("starting")
|
||||||
|
log.WithFields(log.Fields{"app": app, "dst": dst}).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
|
||||||
|
}
|
||||||
|
|
||||||
|
d := Addr(dst)
|
||||||
|
if d.Box() == "" {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "destination box incorrect",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := cfg.box[d.Box()]; !ok {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "destination box doesn't exist",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.Path() == "" {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "destination path incorrect",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if slices.Contains(ac.Destinations, d.String()) {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "destination already exists",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ac.Destinations = append(ac.Destinations, d.String())
|
||||||
|
|
||||||
|
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 ApiAppDestDel(c *gin.Context) {
|
||||||
|
app := c.Param("app")
|
||||||
|
dst := c.Param("dst")
|
||||||
|
dst = dst[1:] // cut first char from wildcard match
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{"app": app, "dst": dst}).Debugf("starting")
|
||||||
|
log.WithFields(log.Fields{"app": app, "dst": dst}).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.Destinations, dst) {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"message": "error",
|
||||||
|
"error": "destination does not exist",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for id, d := range ac.Destinations {
|
||||||
|
if d == dst {
|
||||||
|
ac.Destinations[id] = ac.Destinations[len(ac.Destinations)-1]
|
||||||
|
ac.Destinations = ac.Destinations[:len(ac.Destinations)-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 = "1c2bac4"
|
var githash = "8fdaba6"
|
||||||
var branch = "master"
|
var branch = "master"
|
||||||
var buildstamp = "2026-01-10_11:08:28"
|
var buildstamp = "2026-06-17_20:16:26"
|
||||||
var commits = "134"
|
var commits = "135"
|
||||||
var version = "1c2bac4-b134 - 2026-01-10_11:08:28"
|
var version = "8fdaba6-b135 - 2026-06-17_20:16:26"
|
||||||
|
|||||||
Reference in New Issue
Block a user