mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-07 12:00:44 +08:00
fix(go-document): keep upload partial success data as array (#16661)
### Summary Keep `data` as the uploaded document array when dataset document upload partially succeeds. This matches the Python API behavior and allows parse-on-creation to run for successfully uploaded files when other files in the same folder are unsupported.
This commit is contained in:
@@ -912,7 +912,7 @@ func (h *DocumentHandler) uploadLocalDocuments(c *gin.Context, kb *entity.Knowle
|
||||
|
||||
if strings.ToLower(c.DefaultQuery("return_raw_files", "false")) == "true" {
|
||||
if len(errMsgs) > 0 {
|
||||
common.SuccessNoMessage(c, gin.H{"documents": data, "errors": errMsgs})
|
||||
common.ResponseWithCodeData(c, common.CodeServerError, data, strings.Join(errMsgs, "\n"))
|
||||
return
|
||||
}
|
||||
common.SuccessNoMessage(c, data)
|
||||
@@ -923,7 +923,7 @@ func (h *DocumentHandler) uploadLocalDocuments(c *gin.Context, kb *entity.Knowle
|
||||
mapped[i] = mapDocKeysWithRunStatus(d)
|
||||
}
|
||||
if len(errMsgs) > 0 {
|
||||
common.SuccessNoMessage(c, gin.H{"documents": mapped, "errors": errMsgs})
|
||||
common.ResponseWithCodeData(c, common.CodeServerError, mapped, strings.Join(errMsgs, "\n"))
|
||||
return
|
||||
}
|
||||
common.SuccessNoMessage(c, mapped)
|
||||
|
||||
@@ -692,15 +692,15 @@ func TestUploadDocumentsHandler_LocalReturnsPartialSuccess(t *testing.T) {
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatalf("unmarshal response: %v", err)
|
||||
}
|
||||
if resp["code"] != float64(common.CodeSuccess) {
|
||||
t.Fatalf("expected success for partial upload, got %v", resp)
|
||||
if resp["code"] != float64(common.CodeServerError) {
|
||||
t.Fatalf("expected server error code for partial upload, got %v", resp)
|
||||
}
|
||||
data := resp["data"].(map[string]interface{})
|
||||
if len(data["documents"].([]interface{})) != 1 {
|
||||
t.Fatalf("expected one successful document, got %v", data["documents"])
|
||||
data := resp["data"].([]interface{})
|
||||
if len(data) != 1 {
|
||||
t.Fatalf("expected one successful document, got %v", data)
|
||||
}
|
||||
if len(data["errors"].([]interface{})) != 1 {
|
||||
t.Fatalf("expected one file error, got %v", data["errors"])
|
||||
if !strings.Contains(resp["message"].(string), "bad.exe") {
|
||||
t.Fatalf("expected failed file in message, got %v", resp["message"])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user