Repository navigation
feat(go-api): Align document metadata batch APIs and upload_info with Python - #16269
Conversation
📝 WalkthroughWalkthroughAdds three new authenticated API endpoints: ChangesDocument Upload Info and Batch Metadata Update
Sequence Diagram(s)sequenceDiagram
rect rgba(173, 216, 230, 0.5)
note over Client,FileService: Upload Info Flow
Client->>DocumentHandler: POST /api/v1/documents/upload
DocumentHandler->>DocumentService: UploadDocumentInfos(files) or UploadDocumentInfoByURL(url)
DocumentService->>FileService: UploadInfos(userID, files) or UploadFromURL(tenantID, url)
FileService->>FileService: fetchRemoteFileSafely + SSRF guards
FileService->>FileService: normalizeUploadInfoContent (HTML→markdown, PDF detection)
FileService->>Storage: Put to {userID}-downloads bucket
Storage-->>FileService: stored key
FileService-->>DocumentHandler: descriptor map
DocumentHandler-->>Client: 200 with upload metadata
end
rect rgba(144, 238, 144, 0.5)
note over Client,MetadataStore: Batch Metadata Update Flow
Client->>DocumentHandler: POST/PATCH /datasets/:id/metadata/update
DocumentHandler->>DocumentService: BatchUpdateDocumentMetadatas(datasetID, selector, updates, deletes)
DocumentService->>MetadataStore: SearchMetadata with selector/conditions
MetadataStore-->>DocumentService: matched document IDs
loop each matched document
DocumentService->>MetadataStore: fetch + clone current metadata
DocumentService->>DocumentService: applyDocumentMetadataUpdates + applyDocumentMetadataDeletes
DocumentService->>MetadataStore: UpdateMetadata or DeleteMetadata
end
DocumentService-->>Client: BatchUpdateDocumentMetadatasResponse
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related issues
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/service/document.go`:
- Around line 2295-2298: The validation check in the loop over updates only
verifies that the Key field is not empty but does not check that the Value field
is also provided. Update the conditional in the loop that checks
`strings.TrimSpace(upd.Key) == ""` to also validate that `upd.Value` is not
empty or nil, ensuring both key and value are required for each update before
processing reaches `applyDocumentMetadataUpdates`.
In `@internal/service/file.go`:
- Around line 419-427: The multipart file upload in this function reads the
entire file into memory without size constraints, which can exhaust handler
memory for large authenticated uploads. Wrap the opened file source with
io.LimitedReader using the same maxRemoteFileSize limit that is applied to URL
uploads, then pass the limited reader to io.ReadAll instead of the raw src file
returned by fileHeader.Open().
- Around line 1329-1340: The code currently processes HTML conversion via
htmlToReadableMarkdown before checking for PDF content via bytesLooksLikePDF,
which corrupts binary PDF data when PDFs are served with text/html content type.
Reorder the conditional blocks so that the PDF detection check (the condition
checking lowerCT == "application/pdf" || bytesLooksLikePDF(data)) executes
before the HTML normalization block, ensuring PDF content is identified and
preserved before any markdown conversion is attempted.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 58be9f05-ca7a-436b-b0fa-9b13739b9ec1
📒 Files selected for processing (8)
internal/handler/document.gointernal/handler/document_test.gointernal/router/router.gointernal/service/document.gointernal/service/document_test.gointernal/service/file.gointernal/service/file_test.gointernal/service/metadata.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16269 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Align the Go implementations of these APIs with the Python behavior:
POST /api/v1/datasets/:dataset_id/metadata/updatePATCH /api/v1/datasets/:dataset_id/documents/metadatasPOST /api/v1/documents/uploadWhat changed
matchin update itemsupdatedonly when a document actually changesdocuments/uploadfile uploads with Python-styleupload_infobehavior:.pdfwhen the fetched content is PDFValidation
Unit tests
Passed:
go test ./internal/servicego test ./internal/handlerAlso verified targeted cases for:
curl checks
Verified the new Go endpoints with
curland compared the response shape and behavior with Python for:POST /api/v1/datasets/{dataset_id}/metadata/updatePATCH /api/v1/datasets/{dataset_id}/documents/metadatasPOST /api/v1/documents/uploadThe Go responses were checked against Python for: