From faaac5fbd7f9a769bd72effa46f1b4e4a6ec87cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E6=98=8E?= <83812544+Ed1s0nZ@users.noreply.github.com> Date: Tue, 9 Jun 2026 20:24:53 +0800 Subject: [PATCH] Add files via upload --- internal/handler/conversation.go | 34 ++++++++++++++++++++++++++++---- internal/handler/project.go | 23 ++++++++++++++++++--- internal/handler/robot.go | 4 ++-- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/internal/handler/conversation.go b/internal/handler/conversation.go index 4d5849e3..82215096 100644 --- a/internal/handler/conversation.go +++ b/internal/handler/conversation.go @@ -96,18 +96,44 @@ func (h *ConversationHandler) ListConversations(c *gin.Context) { limit, _ := strconv.Atoi(limitStr) offset, _ := strconv.Atoi(offsetStr) - if limit <= 0 || limit > 100 { + if limit <= 0 { limit = 50 } + if limit > 1000 { + limit = 1000 + } - conversations, err := h.db.ListConversations(limit, offset, search) + excludeGrouped := strings.TrimSpace(search) == "" && + (c.Query("exclude_grouped") == "true" || c.Query("exclude_grouped") == "1") + + var conversations []*database.Conversation + var total int + var err error + if excludeGrouped { + conversations, err = h.db.ListUngroupedConversations(limit, offset) + if err == nil { + total, err = h.db.CountUngroupedConversations() + } + } else { + conversations, err = h.db.ListConversations(limit, offset, search) + if err == nil { + total, err = h.db.CountConversations(search) + } + } if err != nil { h.logger.Error("获取对话列表失败", zap.Error(err)) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } - - c.JSON(http.StatusOK, conversations) + if conversations == nil { + conversations = []*database.Conversation{} + } + c.JSON(http.StatusOK, gin.H{ + "conversations": conversations, + "total": total, + "limit": limit, + "offset": offset, + }) } // GetConversation 获取对话 diff --git a/internal/handler/project.go b/internal/handler/project.go index 98b56b35..588d7619 100644 --- a/internal/handler/project.go +++ b/internal/handler/project.go @@ -85,9 +85,16 @@ func (h *ProjectHandler) GetDashboardSummary(c *gin.Context) { // ListProjects GET /api/projects func (h *ProjectHandler) ListProjects(c *gin.Context) { status := c.Query("status") - limit, _ := strconv.Atoi(c.DefaultQuery("limit", "200")) + search := c.Query("search") + limit, _ := strconv.Atoi(c.DefaultQuery("limit", "50")) offset, _ := strconv.Atoi(c.Query("offset")) - list, err := h.db.ListProjects(status, limit, offset) + if limit <= 0 { + limit = 50 + } + if limit > 500 { + limit = 500 + } + list, err := h.db.ListProjects(status, search, limit, offset) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return @@ -95,7 +102,17 @@ func (h *ProjectHandler) ListProjects(c *gin.Context) { if list == nil { list = []*database.Project{} } - c.JSON(http.StatusOK, list) + total, err := h.db.CountProjects(status, search) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "projects": list, + "total": total, + "limit": limit, + "offset": offset, + }) } // GetProjectStats GET /api/projects/:id/stats diff --git a/internal/handler/robot.go b/internal/handler/robot.go index d8637fa7..ca332869 100644 --- a/internal/handler/robot.go +++ b/internal/handler/robot.go @@ -314,7 +314,7 @@ func (h *RobotHandler) resolveProjectByIDOrName(idOrName string) (*database.Proj if p, err := h.db.GetProject(idOrName); err == nil { return p, "" } - list, err := h.db.ListProjects("", 200, 0) + list, err := h.db.ListProjects("", "", 200, 0) if err != nil { return nil, "查询项目失败: " + err.Error() } @@ -353,7 +353,7 @@ func (h *RobotHandler) cmdProjects() string { if !h.projectsEnabled() { return "项目功能未启用(config.project.enabled)。" } - list, err := h.db.ListProjects("", 50, 0) + list, err := h.db.ListProjects("", "", 50, 0) if err != nil { return "获取项目列表失败: " + err.Error() }