Add files via upload

This commit is contained in:
公明
2026-06-09 20:24:53 +08:00
committed by GitHub
parent 3392fefedf
commit faaac5fbd7
3 changed files with 52 additions and 9 deletions
+30 -4
View File
@@ -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 获取对话
+20 -3
View File
@@ -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
+2 -2
View File
@@ -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()
}