mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-21 15:11:08 +08:00
fix(go): agent explore thumbnail loading for multiple doc_ids (#16514)
## Summary - align the Go `/api/v1/thumbnails` endpoint with the frontend request format for repeated `doc_ids` - return thumbnail mappings for multiple documents instead of failing on a single missing document - preserve Python-compatible thumbnail formatting, including base64 thumbnail passthrough
This commit is contained in:
@@ -52,7 +52,7 @@ type documentServiceIface interface {
|
||||
ListDocuments(page, pageSize int) ([]*service.DocumentResponse, int64, error)
|
||||
ListDocumentsByDatasetID(kbID string, page, pageSize int) ([]*entity.DocumentListItem, int64, error)
|
||||
GetDocumentsByAuthorID(authorID, page, pageSize int) ([]*service.DocumentResponse, int64, error)
|
||||
GetThumbnail(docID string) (*service.ThumbnailResponse, error)
|
||||
GetThumbnails(userID string, docIDs []string) (map[string]string, error)
|
||||
GetDocumentImage(imageID string) ([]byte, error)
|
||||
GetMetadataSummary(kbID string, docIDs []string) (map[string]interface{}, error)
|
||||
SetDocumentMetadata(docID string, meta map[string]interface{}) error
|
||||
@@ -168,40 +168,51 @@ func (h *DocumentHandler) GetDocumentByID(c *gin.Context) {
|
||||
|
||||
// GetThumbnail Get thumbnails for documents.
|
||||
func (h *DocumentHandler) GetThumbnail(c *gin.Context) {
|
||||
_, errorCode, errorMessage := GetUser(c)
|
||||
user, errorCode, errorMessage := GetUser(c)
|
||||
if errorCode != common.CodeSuccess {
|
||||
jsonError(c, errorCode, errorMessage)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Query("doc_ids")
|
||||
if id == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": errors.New("invalid document id"),
|
||||
})
|
||||
docIDs := parseThumbnailDocIDs(c)
|
||||
if len(docIDs) == 0 {
|
||||
jsonError(c, common.CodeArgumentError, `Lack of "Document ID"`)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.documentService.GetThumbnail(id)
|
||||
result, err := h.documentService.GetThumbnails(user.ID, docIDs)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"error": fmt.Errorf("thumbnail not found"),
|
||||
})
|
||||
jsonError(c, common.CodeServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if result.Thumbnail != nil && *result.Thumbnail != "" {
|
||||
newThumbURL := fmt.Sprintf("/api/v1/documents/images/%s-%s", result.KbID, *result.Thumbnail)
|
||||
result.Thumbnail = &newThumbURL
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeSuccess,
|
||||
"data": map[string]interface{}{result.ID: result.Thumbnail},
|
||||
"data": result,
|
||||
"message": "success",
|
||||
})
|
||||
}
|
||||
|
||||
func parseThumbnailDocIDs(c *gin.Context) []string {
|
||||
rawValues := c.QueryArray("doc_ids")
|
||||
seen := make(map[string]struct{}, len(rawValues))
|
||||
docIDs := make([]string, 0, len(rawValues))
|
||||
|
||||
for _, raw := range rawValues {
|
||||
id := strings.TrimSpace(raw)
|
||||
if id == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[id]; ok {
|
||||
continue
|
||||
}
|
||||
seen[id] = struct{}{}
|
||||
docIDs = append(docIDs, id)
|
||||
}
|
||||
|
||||
return docIDs
|
||||
}
|
||||
|
||||
// GetDocumentImage returns a document image from object storage.
|
||||
func (h *DocumentHandler) GetDocumentImage(c *gin.Context) {
|
||||
imageID := c.Param("image_id")
|
||||
|
||||
Reference in New Issue
Block a user