修复搜索日志num不起作用

This commit is contained in:
‘Liu 2024-01-10 14:37:35 +08:00
parent 3d9b81c706
commit 8383bce459
2 changed files with 8 additions and 2 deletions

View File

@ -1,11 +1,12 @@
package controller package controller
import ( import (
"github.com/gin-gonic/gin"
"net/http" "net/http"
"one-api/common" "one-api/common"
"one-api/model" "one-api/model"
"strconv" "strconv"
"github.com/gin-gonic/gin"
) )
func GetAllLogs(c *gin.Context) { func GetAllLogs(c *gin.Context) {
@ -38,10 +39,14 @@ func GetAllLogs(c *gin.Context) {
func GetLogsByKey(c *gin.Context) { func GetLogsByKey(c *gin.Context) {
startidx, _ := strconv.Atoi(c.Query("startIdx")) startidx, _ := strconv.Atoi(c.Query("startIdx"))
num, _ := strconv.Atoi(c.Query("num")) num, _ := strconv.Atoi(c.Query("num"))
if startidx <= 0 || num <= 0 {
if startidx <= 0 {
startidx = 0 startidx = 0
}
if num <= 0 {
num = 10 num = 10
} }
logType, _ := strconv.Atoi(c.Query("type")) logType, _ := strconv.Atoi(c.Query("type"))
startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64) startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64) endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)

View File

@ -73,6 +73,7 @@ func RecordConsumeLog(ctx context.Context, userId int, channelId int, promptToke
} }
func GetLogsByKey(logType int, startTimestamp int64, endTimestamp int64, key string, startIdx int, num int) (logs []*Log, err error) { func GetLogsByKey(logType int, startTimestamp int64, endTimestamp int64, key string, startIdx int, num int) (logs []*Log, err error) {
var tx *gorm.DB var tx *gorm.DB
fmt.Println(num)
token, err := GetNameByToken(key) token, err := GetNameByToken(key)
if logType == LogTypeUnknown { if logType == LogTypeUnknown {
tx = DB.Debug() tx = DB.Debug()