From 3aa0a852a2ff7a5a73904434057f819e70a08a3f Mon Sep 17 00:00:00 2001 From: shoopea Date: Sun, 28 Dec 2025 22:17:53 +0100 Subject: [PATCH] fix wildcard --- admin.go | 4 ++-- api.go | 59 +++++++++++++++++++++++++++++------------------------- version.go | 8 ++++---- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/admin.go b/admin.go index 0524a58..66db2ad 100644 --- a/admin.go +++ b/admin.go @@ -70,8 +70,8 @@ func (a *AdminConfig) Run() { r.GET("/app/deactivate/:app", ApiAppDeactivate) r.GET("/app/:app/source/list", ApiAppSourceList) - r.GET("/app/:app/source/add/:src", ApiAppSourceAdd) - r.GET("/app/:app/source/del/:src", ApiAppSourceDel) + r.GET("/app/:app/source/add/*src", ApiAppSourceAdd) + r.GET("/app/:app/source/del/*src", ApiAppSourceDel) srv := &http.Server{ Addr: a.Addr, diff --git a/api.go b/api.go index d91b446..69e0bdc 100644 --- a/api.go +++ b/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", diff --git a/version.go b/version.go index 1a36b8c..9834017 100644 --- a/version.go +++ b/version.go @@ -1,7 +1,7 @@ // Code generated by version.sh (@generated) DO NOT EDIT. package main -var githash = "f47ddd1" +var githash = "54d8576" var branch = "master" -var buildstamp = "2025-12-28_21:12:44" -var commits = "128" -var version = "f47ddd1-b128 - 2025-12-28_21:12:44" +var buildstamp = "2025-12-28_21:17:45" +var commits = "129" +var version = "54d8576-b129 - 2025-12-28_21:17:45"