From 1890050a309d6de29f3967361ad1812f6be820c3 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 27 Dec 2025 22:00:19 +0100 Subject: [PATCH] app add/del --- api.go | 67 +++++++++++++++++++++++++++++++++++++++++++++++++----- version.go | 8 +++---- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/api.go b/api.go index 2379825..133f0e0 100644 --- a/api.go +++ b/api.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "net/http" + "slices" "time" "github.com/gin-gonic/gin" @@ -72,6 +73,7 @@ func ApiSnapshotList(c *gin.Context) { } } +// FIXME func ApiScheduleAdd(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{ "message": "error", @@ -79,6 +81,7 @@ func ApiScheduleAdd(c *gin.Context) { }) } +// FIXME func ApiScheduleDel(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{ "message": "error", @@ -86,6 +89,7 @@ func ApiScheduleDel(c *gin.Context) { }) } +// FIXME func ApiScheduleList(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{ "message": "error", @@ -166,6 +170,9 @@ func ApiAppList(c *gin.Context) { for _, app := range cfg.apps { list = append(list, app.name) } + + slices.Sort(list) + b, err := json.Marshal(list) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{ @@ -178,15 +185,63 @@ func ApiAppList(c *gin.Context) { } func ApiAppAdd(c *gin.Context) { - c.JSON(http.StatusInternalServerError, gin.H{ - "message": "error", - "error": "not implemented", + name := c.Param("app") + found := false + for _, app := range cfg.Apps { + if app.Name == name { + found = true + } + } + if found { + c.JSON(http.StatusInternalServerError, gin.H{ + "message": "error", + "error": "app already exist", + }) + return + } + app := &AppConfig{ + Name: name, + Active: false, + } + cfg.Apps = append(cfg.Apps, app) + err := cfg.Save() + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "message": "error", + "error": err, + }) + return + } + c.JSON(http.StatusOK, gin.H{ + "message": "done", }) } func ApiAppDel(c *gin.Context) { - c.JSON(http.StatusInternalServerError, gin.H{ - "message": "error", - "error": "not implemented", + name := c.Param("app") + found := false + for id, app := range cfg.Apps { + if app.Name == name { + if app.Active { + c.JSON(http.StatusInternalServerError, gin.H{ + "message": "error", + "error": "app still active", + }) + return + } + found = true + cfg.Apps[id] = cfg.Apps[len(cfg.Apps)-1] + cfg.Apps = cfg.Apps[:len(cfg.Apps)-1] + } + } + if !found { + c.JSON(http.StatusInternalServerError, gin.H{ + "message": "error", + "error": "no app found", + }) + return + } + c.JSON(http.StatusOK, gin.H{ + "message": "done", }) } diff --git a/version.go b/version.go index 909f4f6..99ceeb4 100644 --- a/version.go +++ b/version.go @@ -1,7 +1,7 @@ // Code generated by version.sh (@generated) DO NOT EDIT. package main -var githash = "a1ba422" +var githash = "3e867da" var branch = "master" -var buildstamp = "2025-12-27_18:34:17" -var commits = "117" -var version = "a1ba422-b117 - 2025-12-27_18:34:17" +var buildstamp = "2025-12-27_20:59:37" +var commits = "118" +var version = "3e867da-b118 - 2025-12-27_20:59:37"