Changeset 0.21.2 (#88)
This commit is contained in:
@@ -394,6 +394,46 @@ func (h *WorkspaceHandler) Stats(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, stats)
|
||||
}
|
||||
|
||||
// IndexStatus returns indexing progress for all files in the workspace (v0.21.2).
|
||||
func (h *WorkspaceHandler) IndexStatus(c *gin.Context) {
|
||||
w, ok := h.loadAndAuthorize(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := c.Request.Context()
|
||||
files, err := h.stores.Workspaces.ListFiles(ctx, w.ID, "", true)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to list files"})
|
||||
return
|
||||
}
|
||||
|
||||
// Aggregate counts by status
|
||||
counts := map[string]int{
|
||||
"pending": 0, "indexing": 0, "ready": 0,
|
||||
"error": 0, "skipped": 0,
|
||||
}
|
||||
totalChunks := 0
|
||||
for _, f := range files {
|
||||
if f.IsDirectory {
|
||||
continue
|
||||
}
|
||||
status := f.IndexStatus
|
||||
if status == "" {
|
||||
status = "pending"
|
||||
}
|
||||
counts[status]++
|
||||
totalChunks += f.ChunkCount
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"workspace_id": w.ID,
|
||||
"indexing_enabled": w.IndexingEnabled,
|
||||
"status_counts": counts,
|
||||
"total_chunks": totalChunks,
|
||||
})
|
||||
}
|
||||
|
||||
// ── Authorization Helpers ───────────────────
|
||||
|
||||
// loadAndAuthorize loads a workspace by :id param and checks user access.
|
||||
|
||||
Reference in New Issue
Block a user