app add/del
This commit is contained in:
67
api.go
67
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",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user