fix wildcard
This commit is contained in:
59
api.go
59
api.go
@@ -473,20 +473,23 @@ func ApiAppSourceList(c *gin.Context) {
|
||||
}
|
||||
|
||||
func ApiAppSourceAdd(c *gin.Context) {
|
||||
log.WithFields(log.Fields{"app": c.Param("app"), "src": c.Param("src")}).Debugf("starting")
|
||||
log.WithFields(log.Fields{"app": c.Param("app"), "src": c.Param("src")}).Debugf("done")
|
||||
app := c.Param("app")
|
||||
src := c.Param("src")
|
||||
src = src[1:] // cut first char from wildcard match
|
||||
|
||||
log.WithFields(log.Fields{"app": app, "src": src}).Debugf("starting")
|
||||
log.WithFields(log.Fields{"app": app, "src": src}).Debugf("done")
|
||||
|
||||
name := c.Param("app")
|
||||
found := false
|
||||
app := &AppConfig{}
|
||||
ac := &AppConfig{}
|
||||
|
||||
CfgLock()
|
||||
defer CfgUnlock()
|
||||
|
||||
for _, a := range cfg.Apps {
|
||||
if a.Name == name {
|
||||
if a.Name == app {
|
||||
found = true
|
||||
app = a
|
||||
ac = a
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,8 +501,8 @@ func ApiAppSourceAdd(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
src := Addr(c.Param("src"))
|
||||
if src.Box() == "" {
|
||||
s := Addr(src)
|
||||
if s.Box() == "" {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": "error",
|
||||
"error": "source box incorrect",
|
||||
@@ -507,7 +510,7 @@ func ApiAppSourceAdd(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := cfg.box[src.Box()]; !ok {
|
||||
if _, ok := cfg.box[s.Box()]; !ok {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": "error",
|
||||
"error": "source box doesn't exist",
|
||||
@@ -515,7 +518,7 @@ func ApiAppSourceAdd(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if src.Path() == "" {
|
||||
if s.Path() == "" {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": "error",
|
||||
"error": "source path incorrect",
|
||||
@@ -523,7 +526,7 @@ func ApiAppSourceAdd(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if slices.Contains(app.Sources, src.String()) {
|
||||
if slices.Contains(ac.Sources, s.String()) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": "error",
|
||||
"error": "source already exists",
|
||||
@@ -531,10 +534,10 @@ func ApiAppSourceAdd(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
app.Sources = append(app.Sources, src.String())
|
||||
ac.Sources = append(ac.Sources, s.String())
|
||||
|
||||
if app.Active {
|
||||
a, err := cfg.NewApp(app.Name, app.Sources, app.Destinations, app.Schedule, app.Before, app.After)
|
||||
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",
|
||||
@@ -562,20 +565,23 @@ func ApiAppSourceAdd(c *gin.Context) {
|
||||
}
|
||||
|
||||
func ApiAppSourceDel(c *gin.Context) {
|
||||
log.WithFields(log.Fields{"app": c.Param("app"), "src": c.Param("src")}).Debugf("starting")
|
||||
log.WithFields(log.Fields{"app": c.Param("app"), "src": c.Param("src")}).Debugf("done")
|
||||
app := c.Param("app")
|
||||
src := c.Param("src")
|
||||
src = src[1:] // cut first char from wildcard match
|
||||
|
||||
log.WithFields(log.Fields{"app": app, "src": src}).Debugf("starting")
|
||||
log.WithFields(log.Fields{"app": app, "src": src}).Debugf("done")
|
||||
|
||||
name := c.Param("app")
|
||||
found := false
|
||||
app := &AppConfig{}
|
||||
ac := &AppConfig{}
|
||||
|
||||
CfgLock()
|
||||
defer CfgUnlock()
|
||||
|
||||
for _, a := range cfg.Apps {
|
||||
if a.Name == name {
|
||||
if a.Name == app {
|
||||
found = true
|
||||
app = a
|
||||
ac = a
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,8 +593,7 @@ func ApiAppSourceDel(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
src := c.Param("src")
|
||||
if !slices.Contains(app.Sources, src) {
|
||||
if !slices.Contains(ac.Sources, src) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": "error",
|
||||
"error": "source does not exist",
|
||||
@@ -596,15 +601,15 @@ func ApiAppSourceDel(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
for id, s := range app.Sources {
|
||||
for id, s := range ac.Sources {
|
||||
if s == src {
|
||||
app.Sources[id] = app.Sources[len(app.Sources)-1]
|
||||
app.Sources = app.Sources[:len(app.Sources)-1]
|
||||
ac.Sources[id] = ac.Sources[len(ac.Sources)-1]
|
||||
ac.Sources = ac.Sources[:len(ac.Sources)-1]
|
||||
}
|
||||
}
|
||||
|
||||
if app.Active {
|
||||
a, err := cfg.NewApp(app.Name, app.Sources, app.Destinations, app.Schedule, app.Before, app.After)
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user