提交5个文件, 修改了mongo方法, 如果token获取错误, 然后获取完租户id后, 把错误清除

This commit is contained in:
Cold
2025-12-24 18:33:11 +08:00
committed by 张斌
parent 3dc3ebc9ad
commit ecf3c29759
5 changed files with 88 additions and 41 deletions

View File

@@ -5,10 +5,10 @@ package ragflow
import (
"bytes"
"context"
"encoding/json"
"mime/multipart"
"strings"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
)
@@ -44,6 +44,11 @@ type UploadDocumentReq struct {
FilePaths []string // 本地文件路径列表
}
// UploadDocumentRes 上传文档响应
type UploadDocumentRes struct {
Id string `json:"id"` // 文档ID
}
// ListDocumentsReq 列出文档请求
type ListDocumentsReq struct {
Page int `json:"page,omitempty"` // 页码,默认 1
@@ -190,28 +195,25 @@ func (c *Client) UploadDocumentFromText(ctx context.Context, datasetId, content,
defer resp.Close()
// 解析响应
var result struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
Id string `json:"id"`
} `json:"data"`
var response struct {
Code int `json:"code"`
Message string `json:"message"`
Data []UploadDocumentRes `json:"data"` // RAGFlow返回数组
}
bodyBytes := resp.ReadAll()
if err = gjson.DecodeTo(bodyBytes, &result); err != nil {
return "", err
if err := json.Unmarshal(resp.ReadAll(), &response); err != nil {
return "", gerror.Newf("json Decode failed: %v", err)
}
if result.Code != 0 {
return "", gerror.Newf("上传文档失败 (code=%d): %s", result.Code, result.Message)
if len(response.Data) == 0 {
return "", gerror.New("上传文档返回data为空")
}
if result.Data.Id == "" {
return "", gerror.New("上传成功但未返回文档ID")
if response.Code != 0 {
return "", gerror.Newf("上传文档失败 (code=%d): %s", response.Code, response.Message)
}
return result.Data.Id, nil
return response.Data[0].Id, nil
}
// UploadDocument 上传文档(保留兼容)