app add/del
This commit is contained in:
67
api.go
67
api.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -72,6 +73,7 @@ func ApiSnapshotList(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
func ApiScheduleAdd(c *gin.Context) {
|
func ApiScheduleAdd(c *gin.Context) {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": "error",
|
"message": "error",
|
||||||
@@ -79,6 +81,7 @@ func ApiScheduleAdd(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
func ApiScheduleDel(c *gin.Context) {
|
func ApiScheduleDel(c *gin.Context) {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": "error",
|
"message": "error",
|
||||||
@@ -86,6 +89,7 @@ func ApiScheduleDel(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
func ApiScheduleList(c *gin.Context) {
|
func ApiScheduleList(c *gin.Context) {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": "error",
|
"message": "error",
|
||||||
@@ -166,6 +170,9 @@ func ApiAppList(c *gin.Context) {
|
|||||||
for _, app := range cfg.apps {
|
for _, app := range cfg.apps {
|
||||||
list = append(list, app.name)
|
list = append(list, app.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slices.Sort(list)
|
||||||
|
|
||||||
b, err := json.Marshal(list)
|
b, err := json.Marshal(list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
@@ -178,15 +185,63 @@ func ApiAppList(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ApiAppAdd(c *gin.Context) {
|
func ApiAppAdd(c *gin.Context) {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
name := c.Param("app")
|
||||||
"message": "error",
|
found := false
|
||||||
"error": "not implemented",
|
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) {
|
func ApiAppDel(c *gin.Context) {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
name := c.Param("app")
|
||||||
"message": "error",
|
found := false
|
||||||
"error": "not implemented",
|
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",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 = "a1ba422"
|
var githash = "3e867da"
|
||||||
var branch = "master"
|
var branch = "master"
|
||||||
var buildstamp = "2025-12-27_18:34:17"
|
var buildstamp = "2025-12-27_20:59:37"
|
||||||
var commits = "117"
|
var commits = "118"
|
||||||
var version = "a1ba422-b117 - 2025-12-27_18:34:17"
|
var version = "3e867da-b118 - 2025-12-27_20:59:37"
|
||||||
|
|||||||
Reference in New Issue
Block a user