feat: multi-feature update
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/constant"
|
||||
@@ -18,6 +19,8 @@ import (
|
||||
"github.com/QuantumNous/new-api/setting/system_setting"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
)
|
||||
|
||||
func TestStatus(c *gin.Context) {
|
||||
@@ -144,6 +147,7 @@ func GetStatus(c *gin.Context) {
|
||||
ClientId string `json:"client_id"`
|
||||
AuthorizationEndpoint string `json:"authorization_endpoint"`
|
||||
Scopes string `json:"scopes"`
|
||||
PKCEEnabled bool `json:"pkce_enabled"`
|
||||
}
|
||||
providersInfo := make([]CustomOAuthInfo, 0, len(customProviders))
|
||||
for _, p := range customProviders {
|
||||
@@ -156,6 +160,7 @@ func GetStatus(c *gin.Context) {
|
||||
ClientId: config.ClientId,
|
||||
AuthorizationEndpoint: config.AuthorizationEndpoint,
|
||||
Scopes: config.Scopes,
|
||||
PKCEEnabled: config.PKCEEnabled,
|
||||
})
|
||||
}
|
||||
data["custom_oauth_providers"] = providersInfo
|
||||
@@ -231,6 +236,49 @@ func GetHomePageContent(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
func GetHomeStats(c *gin.Context) {
|
||||
var cpuUsage float64
|
||||
if percents, err := cpu.Percent(150*time.Millisecond, false); err == nil && len(percents) > 0 {
|
||||
cpuUsage = percents[0]
|
||||
} else {
|
||||
cpuUsage = common.GetSystemStatus().CPUUsage
|
||||
}
|
||||
|
||||
var memoryTotal uint64
|
||||
var memoryUsed uint64
|
||||
var memoryUsage float64
|
||||
if memInfo, err := mem.VirtualMemory(); err == nil {
|
||||
memoryTotal = memInfo.Total
|
||||
memoryUsed = memInfo.Used
|
||||
memoryUsage = memInfo.UsedPercent
|
||||
} else {
|
||||
memoryUsage = common.GetSystemStatus().MemoryUsage
|
||||
}
|
||||
|
||||
totalTokens, err := model.SumTotalConsumeTokens()
|
||||
if err != nil {
|
||||
logger.LogError(c.Request.Context(), "failed to query home stats token usage: "+err.Error())
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "查询首页统计失败",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"message": "",
|
||||
"data": gin.H{
|
||||
"cpu_usage": cpuUsage,
|
||||
"memory_usage": memoryUsage,
|
||||
"memory_total": memoryTotal,
|
||||
"memory_used": memoryUsed,
|
||||
"total_tokens": totalTokens,
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func SendEmailVerification(c *gin.Context) {
|
||||
email := c.Query("email")
|
||||
if err := common.Validate.Var(email, "required,email"); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user