fix wildcard

This commit is contained in:
shoopea
2025-12-28 22:17:53 +01:00
parent 54d85767a7
commit 3aa0a852a2
3 changed files with 38 additions and 33 deletions

View File

@@ -70,8 +70,8 @@ func (a *AdminConfig) Run() {
r.GET("/app/deactivate/:app", ApiAppDeactivate) r.GET("/app/deactivate/:app", ApiAppDeactivate)
r.GET("/app/:app/source/list", ApiAppSourceList) r.GET("/app/:app/source/list", ApiAppSourceList)
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)
srv := &http.Server{ srv := &http.Server{
Addr: a.Addr, Addr: a.Addr,

59
api.go
View File

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

View File

@@ -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 = "f47ddd1" var githash = "54d8576"
var branch = "master" var branch = "master"
var buildstamp = "2025-12-28_21:12:44" var buildstamp = "2025-12-28_21:17:45"
var commits = "128" var commits = "129"
var version = "f47ddd1-b128 - 2025-12-28_21:12:44" var version = "54d8576-b129 - 2025-12-28_21:17:45"