update app list

This commit is contained in:
shoopea
2026-01-10 12:02:15 +01:00
parent 551651b9d2
commit 1c2bac4116
3 changed files with 78 additions and 51 deletions

117
api.go
View File

@@ -124,53 +124,22 @@ func ApiRunApp(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
active := false
var (
app *App
err error
)
for _, a := range cfg.Apps {
if a.Name == name {
found = true
active = a.Active
app, err = cfg.NewApp(a.Name, a.Sources, a.Destinations, a.Schedule, a.Before, a.After)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"message": "error",
"error": fmt.Sprint(err),
})
return
}
if app, ok := cfg.apps[c.Param("app")]; ok {
if err := app.RunStandaloneTime(time.Now()); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"message": "error",
"error": fmt.Sprint(err),
})
} else {
c.JSON(http.StatusOK, gin.H{
"message": "done",
})
}
}
if !found {
c.JSON(http.StatusInternalServerError, gin.H{
"message": "error",
"error": "no app found",
})
return
}
if !active {
c.JSON(http.StatusInternalServerError, gin.H{
"message": "error",
"error": "app not active",
})
return
}
if err := app.RunStandaloneTime(time.Now()); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"message": "error",
"error": fmt.Sprint(err),
})
} else {
c.JSON(http.StatusOK, gin.H{
"message": "done",
c.JSON(http.StatusInternalServerError, gin.H{
"message": "error",
"app": c.Param("app"),
"error": "no active app found",
})
}
}
@@ -262,7 +231,7 @@ func ApiAppList(c *gin.Context) {
c.Data(http.StatusOK, "application/json", pretty.PrettyOptions(b, &pretty.Options{Indent: " "}))
}
func ApiListSchedule(c *gin.Context) {
func ApiAppListSchedule(c *gin.Context) {
log.WithFields(log.Fields{"schedule": c.Param("schedule")}).Debugf("starting")
log.WithFields(log.Fields{"schedule": c.Param("schedule")}).Debugf("done")
@@ -293,6 +262,62 @@ func ApiListSchedule(c *gin.Context) {
c.Data(http.StatusOK, "application/json", pretty.PrettyOptions(b, &pretty.Options{Indent: " "}))
}
func ApiAppListActive(c *gin.Context) {
log.WithFields(log.Fields{}).Debugf("starting")
log.WithFields(log.Fields{}).Debugf("done")
list := make([]string, 0)
CfgLock()
defer CfgUnlock()
for _, app := range cfg.Apps {
if app.Active {
list = append(list, app.Name)
}
}
slices.Sort(list)
b, err := json.Marshal(list)
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 ApiAppListInactive(c *gin.Context) {
log.WithFields(log.Fields{}).Debugf("starting")
log.WithFields(log.Fields{}).Debugf("done")
list := make([]string, 0)
CfgLock()
defer CfgUnlock()
for _, app := range cfg.Apps {
if !app.Active {
list = append(list, app.Name)
}
}
slices.Sort(list)
b, err := json.Marshal(list)
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 ApiAppAdd(c *gin.Context) {
log.WithFields(log.Fields{"app": c.Param("app")}).Debugf("starting")
log.WithFields(log.Fields{"app": c.Param("app")}).Debugf("done")