mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-16 21:23:44 +08:00
🔖 chore: logs list displays channel name.
This commit is contained in:
20
model/log.go
20
model/log.go
@@ -20,8 +20,10 @@ type Log struct {
|
||||
Quota int `json:"quota" gorm:"default:0"`
|
||||
PromptTokens int `json:"prompt_tokens" gorm:"default:0"`
|
||||
CompletionTokens int `json:"completion_tokens" gorm:"default:0"`
|
||||
ChannelId int `json:"channel" gorm:"index"`
|
||||
ChannelId int `json:"channel_id" gorm:"index"`
|
||||
RequestTime int `json:"request_time" gorm:"default:0"`
|
||||
|
||||
Channel *Channel `json:"channel" gorm:"foreignKey:Id;references:ChannelId"`
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -82,7 +84,7 @@ type LogsListParams struct {
|
||||
ModelName string `form:"model_name"`
|
||||
Username string `form:"username"`
|
||||
TokenName string `form:"token_name"`
|
||||
Channel int `form:"channel"`
|
||||
ChannelId int `form:"channel_id"`
|
||||
}
|
||||
|
||||
var allowedLogsOrderFields = map[string]bool{
|
||||
@@ -98,10 +100,12 @@ func GetLogsList(params *LogsListParams) (*DataResult[Log], error) {
|
||||
var tx *gorm.DB
|
||||
var logs []*Log
|
||||
|
||||
if params.LogType == LogTypeUnknown {
|
||||
tx = DB
|
||||
} else {
|
||||
tx = DB.Where("type = ?", params.LogType)
|
||||
tx = DB.Preload("Channel", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("id, name")
|
||||
})
|
||||
|
||||
if params.LogType != LogTypeUnknown {
|
||||
tx = tx.Where("type = ?", params.LogType)
|
||||
}
|
||||
if params.ModelName != "" {
|
||||
tx = tx.Where("model_name = ?", params.ModelName)
|
||||
@@ -118,8 +122,8 @@ func GetLogsList(params *LogsListParams) (*DataResult[Log], error) {
|
||||
if params.EndTimestamp != 0 {
|
||||
tx = tx.Where("created_at <= ?", params.EndTimestamp)
|
||||
}
|
||||
if params.Channel != 0 {
|
||||
tx = tx.Where("channel_id = ?", params.Channel)
|
||||
if params.ChannelId != 0 {
|
||||
tx = tx.Where("channel_id = ?", params.ChannelId)
|
||||
}
|
||||
|
||||
return PaginateAndOrder[Log](tx, ¶ms.PaginationParams, &logs, allowedLogsOrderFields)
|
||||
|
||||
Reference in New Issue
Block a user