forked from QuantumNous/new-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_info.go
More file actions
65 lines (54 loc) · 1.31 KB
/
Copy pathsystem_info.go
File metadata and controls
65 lines (54 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package controller
import (
"net/http"
"strings"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/model"
"github.com/gin-gonic/gin"
)
func ListSystemInstances(c *gin.Context) {
instances, err := model.ListSystemInstances()
if err != nil {
common.ApiError(c, err)
return
}
now := common.GetTimestamp()
responses := make([]model.SystemInstanceResponse, 0, len(instances))
for _, instance := range instances {
responses = append(responses, instance.ToResponse(now))
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": responses,
})
}
func DeleteStaleSystemInstances(c *gin.Context) {
deletedCount, err := model.DeleteStaleSystemInstances(common.GetTimestamp())
if err != nil {
common.ApiError(c, err)
return
}
common.ApiSuccess(c, gin.H{
"deleted_count": deletedCount,
})
}
func DeleteStaleSystemInstance(c *gin.Context) {
nodeName := c.Param("node_name")
if strings.TrimSpace(nodeName) == "" {
common.ApiErrorMsg(c, "node name is required")
return
}
deleted, err := model.DeleteStaleSystemInstance(nodeName, common.GetTimestamp())
if err != nil {
common.ApiError(c, err)
return
}
if !deleted {
common.ApiErrorMsg(c, "instance is not stale or no longer exists")
return
}
common.ApiSuccess(c, gin.H{
"deleted_count": 1,
})
}