|
|
@@ -2,6 +2,7 @@ package controller
|
|
|
|
|
|
import (
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "net/http"
|
|
|
"one-api/common"
|
|
|
"one-api/model"
|
|
|
"strconv"
|
|
|
@@ -20,17 +21,18 @@ func GetAllLogs(c *gin.Context) {
|
|
|
modelName := c.Query("model_name")
|
|
|
logs, err := model.GetAllLogs(logType, startTimestamp, endTimestamp, modelName, username, tokenName, p*common.ItemsPerPage, common.ItemsPerPage)
|
|
|
if err != nil {
|
|
|
- c.JSON(200, gin.H{
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
"success": false,
|
|
|
"message": err.Error(),
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- c.JSON(200, gin.H{
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
"success": true,
|
|
|
"message": "",
|
|
|
"data": logs,
|
|
|
})
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func GetUserLogs(c *gin.Context) {
|
|
|
@@ -46,34 +48,36 @@ func GetUserLogs(c *gin.Context) {
|
|
|
modelName := c.Query("model_name")
|
|
|
logs, err := model.GetUserLogs(userId, logType, startTimestamp, endTimestamp, modelName, tokenName, p*common.ItemsPerPage, common.ItemsPerPage)
|
|
|
if err != nil {
|
|
|
- c.JSON(200, gin.H{
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
"success": false,
|
|
|
"message": err.Error(),
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- c.JSON(200, gin.H{
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
"success": true,
|
|
|
"message": "",
|
|
|
"data": logs,
|
|
|
})
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func SearchAllLogs(c *gin.Context) {
|
|
|
keyword := c.Query("keyword")
|
|
|
logs, err := model.SearchAllLogs(keyword)
|
|
|
if err != nil {
|
|
|
- c.JSON(200, gin.H{
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
"success": false,
|
|
|
"message": err.Error(),
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- c.JSON(200, gin.H{
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
"success": true,
|
|
|
"message": "",
|
|
|
"data": logs,
|
|
|
})
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func SearchUserLogs(c *gin.Context) {
|
|
|
@@ -81,17 +85,18 @@ func SearchUserLogs(c *gin.Context) {
|
|
|
userId := c.GetInt("id")
|
|
|
logs, err := model.SearchUserLogs(userId, keyword)
|
|
|
if err != nil {
|
|
|
- c.JSON(200, gin.H{
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
"success": false,
|
|
|
"message": err.Error(),
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- c.JSON(200, gin.H{
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
"success": true,
|
|
|
"message": "",
|
|
|
"data": logs,
|
|
|
})
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func GetLogsStat(c *gin.Context) {
|
|
|
@@ -103,7 +108,7 @@ func GetLogsStat(c *gin.Context) {
|
|
|
modelName := c.Query("model_name")
|
|
|
quotaNum := model.SumUsedQuota(logType, startTimestamp, endTimestamp, modelName, username, tokenName)
|
|
|
//tokenNum := model.SumUsedToken(logType, startTimestamp, endTimestamp, modelName, username, "")
|
|
|
- c.JSON(200, gin.H{
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
"success": true,
|
|
|
"message": "",
|
|
|
"data": gin.H{
|
|
|
@@ -111,6 +116,7 @@ func GetLogsStat(c *gin.Context) {
|
|
|
//"token": tokenNum,
|
|
|
},
|
|
|
})
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func GetLogsSelfStat(c *gin.Context) {
|
|
|
@@ -122,7 +128,7 @@ func GetLogsSelfStat(c *gin.Context) {
|
|
|
modelName := c.Query("model_name")
|
|
|
quotaNum := model.SumUsedQuota(logType, startTimestamp, endTimestamp, modelName, username, tokenName)
|
|
|
//tokenNum := model.SumUsedToken(logType, startTimestamp, endTimestamp, modelName, username, tokenName)
|
|
|
- c.JSON(200, gin.H{
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
"success": true,
|
|
|
"message": "",
|
|
|
"data": gin.H{
|
|
|
@@ -130,4 +136,30 @@ func GetLogsSelfStat(c *gin.Context) {
|
|
|
//"token": tokenNum,
|
|
|
},
|
|
|
})
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func DeleteHistoryLogs(c *gin.Context) {
|
|
|
+ targetTimestamp, _ := strconv.ParseInt(c.Query("target_timestamp"), 10, 64)
|
|
|
+ if targetTimestamp == 0 {
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
+ "success": false,
|
|
|
+ "message": "target timestamp is required",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count, err := model.DeleteOldLog(targetTimestamp)
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
+ "success": false,
|
|
|
+ "message": err.Error(),
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
+ "success": true,
|
|
|
+ "message": "",
|
|
|
+ "data": count,
|
|
|
+ })
|
|
|
+ return
|
|
|
}
|