From 94fa2810ccc26a40efdc4766c31836d74a63fcc6 Mon Sep 17 00:00:00 2001 From: Lilo <1622461+detecti1@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:20:12 +0800 Subject: [PATCH] Add channel name (tooltip / detail) to logs --- model/log.go | 9 +++++++++ web/src/components/LogsTable.js | 25 ++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/model/log.go b/model/log.go index 4a633a6a..dd5a3162 100644 --- a/model/log.go +++ b/model/log.go @@ -27,6 +27,7 @@ type Log struct { UseTime int `json:"use_time" gorm:"default:0"` IsStream bool `json:"is_stream" gorm:"default:false"` ChannelId int `json:"channel" gorm:"index"` + ChannelName string `json:"channel_name" gorm:"->"` TokenId int `json:"token_id" gorm:"default:0;index"` Group string `json:"group" gorm:"index"` Other string `json:"other"` @@ -130,6 +131,10 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName } else { tx = LOG_DB.Where("type = ?", logType) } + + tx = tx.Joins("LEFT JOIN channels ON logs.channel_id = channels.id") + tx = tx.Select("logs.*, channels.name as channel_name") + if modelName != "" { tx = tx.Where("model_name like ?", modelName) } @@ -169,6 +174,10 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int } else { tx = LOG_DB.Where("user_id = ? and type = ?", userId, logType) } + + tx = tx.Joins("LEFT JOIN channels ON logs.channel_id = channels.id") + tx = tx.Select("logs.*, channels.name as channel_name") + if modelName != "" { tx = tx.Where("model_name like ?", modelName) } diff --git a/web/src/components/LogsTable.js b/web/src/components/LogsTable.js index 452585a1..6faee1df 100644 --- a/web/src/components/LogsTable.js +++ b/web/src/components/LogsTable.js @@ -157,13 +157,15 @@ const LogsTable = () => { record.type === 0 || record.type === 2 ? (