mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-07-25 21:31:08 +02:00
Add files via upload
This commit is contained in:
@@ -96,18 +96,44 @@ func (h *ConversationHandler) ListConversations(c *gin.Context) {
|
|||||||
limit, _ := strconv.Atoi(limitStr)
|
limit, _ := strconv.Atoi(limitStr)
|
||||||
offset, _ := strconv.Atoi(offsetStr)
|
offset, _ := strconv.Atoi(offsetStr)
|
||||||
|
|
||||||
if limit <= 0 || limit > 100 {
|
if limit <= 0 {
|
||||||
limit = 50
|
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 {
|
if err != nil {
|
||||||
h.logger.Error("获取对话列表失败", zap.Error(err))
|
h.logger.Error("获取对话列表失败", zap.Error(err))
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if conversations == nil {
|
||||||
c.JSON(http.StatusOK, conversations)
|
conversations = []*database.Conversation{}
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"conversations": conversations,
|
||||||
|
"total": total,
|
||||||
|
"limit": limit,
|
||||||
|
"offset": offset,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConversation 获取对话
|
// GetConversation 获取对话
|
||||||
|
|||||||
@@ -85,9 +85,16 @@ func (h *ProjectHandler) GetDashboardSummary(c *gin.Context) {
|
|||||||
// ListProjects GET /api/projects
|
// ListProjects GET /api/projects
|
||||||
func (h *ProjectHandler) ListProjects(c *gin.Context) {
|
func (h *ProjectHandler) ListProjects(c *gin.Context) {
|
||||||
status := c.Query("status")
|
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"))
|
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 {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
@@ -95,7 +102,17 @@ func (h *ProjectHandler) ListProjects(c *gin.Context) {
|
|||||||
if list == nil {
|
if list == nil {
|
||||||
list = []*database.Project{}
|
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
|
// GetProjectStats GET /api/projects/:id/stats
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ func (h *RobotHandler) resolveProjectByIDOrName(idOrName string) (*database.Proj
|
|||||||
if p, err := h.db.GetProject(idOrName); err == nil {
|
if p, err := h.db.GetProject(idOrName); err == nil {
|
||||||
return p, ""
|
return p, ""
|
||||||
}
|
}
|
||||||
list, err := h.db.ListProjects("", 200, 0)
|
list, err := h.db.ListProjects("", "", 200, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "查询项目失败: " + err.Error()
|
return nil, "查询项目失败: " + err.Error()
|
||||||
}
|
}
|
||||||
@@ -353,7 +353,7 @@ func (h *RobotHandler) cmdProjects() string {
|
|||||||
if !h.projectsEnabled() {
|
if !h.projectsEnabled() {
|
||||||
return "项目功能未启用(config.project.enabled)。"
|
return "项目功能未启用(config.project.enabled)。"
|
||||||
}
|
}
|
||||||
list, err := h.db.ListProjects("", 50, 0)
|
list, err := h.db.ListProjects("", "", 50, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "获取项目列表失败: " + err.Error()
|
return "获取项目列表失败: " + err.Error()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user