From 94a9b0c00fb5e389ed908fa57ce928178de1ba8a Mon Sep 17 00:00:00 2001 From: tbphp Date: Sat, 5 Jul 2025 10:15:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BF=87=E6=BB=A4=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/handler/group_handler.go | 58 +++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/internal/handler/group_handler.go b/internal/handler/group_handler.go index da189b6..373a50a 100644 --- a/internal/handler/group_handler.go +++ b/internal/handler/group_handler.go @@ -13,6 +13,7 @@ import ( "regexp" "strconv" "strings" + "time" "gpt-load/internal/channel" @@ -207,7 +208,7 @@ func (s *Server) CreateGroup(c *gin.Context) { return } - response.Success(c, group) + response.Success(c, newGroupResponse(&group)) } // ListGroups handles listing all groups. @@ -217,7 +218,13 @@ func (s *Server) ListGroups(c *gin.Context) { response.Error(c, app_errors.ParseDBError(err)) return } - response.Success(c, groups) + + var groupResponses []GroupResponse + for _, group := range groups { + groupResponses = append(groupResponses, *newGroupResponse(&group)) + } + + response.Success(c, groupResponses) } // GroupUpdateRequest defines the payload for updating a group. @@ -332,9 +339,46 @@ func (s *Server) UpdateGroup(c *gin.Context) { return } - response.Success(c, group) + response.Success(c, newGroupResponse(&group)) } +// GroupResponse defines the structure for a group response, excluding sensitive or large fields. +type GroupResponse struct { + ID uint `json:"id"` + Name string `json:"name"` + DisplayName string `json:"display_name"` + Description string `json:"description"` + Upstreams datatypes.JSON `json:"upstreams"` + ChannelType string `json:"channel_type"` + Sort int `json:"sort"` + TestModel string `json:"test_model"` + ParamOverrides datatypes.JSONMap `json:"param_overrides"` + Config datatypes.JSONMap `json:"config"` + LastValidatedAt *time.Time `json:"last_validated_at"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + +// newGroupResponse creates a new GroupResponse from a models.Group. +func newGroupResponse(group *models.Group) *GroupResponse { + return &GroupResponse{ + ID: group.ID, + Name: group.Name, + DisplayName: group.DisplayName, + Description: group.Description, + Upstreams: group.Upstreams, + ChannelType: group.ChannelType, + Sort: group.Sort, + TestModel: group.TestModel, + ParamOverrides: group.ParamOverrides, + Config: group.Config, + LastValidatedAt: group.LastValidatedAt, + CreatedAt: group.CreatedAt, + UpdatedAt: group.UpdatedAt, + } +} + + // DeleteGroup handles deleting a group. func (s *Server) DeleteGroup(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) @@ -383,10 +427,10 @@ func (s *Server) DeleteGroup(c *gin.Context) { // ConfigOption represents a single configurable option for a group. type ConfigOption struct { - Key string `json:"key"` - Name string `json:"name"` - Description string `json:"description"` - DefaultValue any `json:"default_value"` + Key string `json:"key"` + Name string `json:"name"` + Description string `json:"description"` + DefaultValue any `json:"default_value"` } // GetGroupConfigOptions returns a list of available configuration options for groups.