mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-05 07:10:29 +08:00
Go: add context to storage (#17690)
Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -75,7 +75,7 @@ type documentServiceIface interface {
|
||||
UploadEmptyDocument(ctx context.Context, kb *entity.Knowledgebase, tenantID, name string) (map[string]interface{}, common.ErrorCode, error)
|
||||
DownloadDocument(ctx context.Context, datasetID, docID string) (*document.DownloadDocumentResp, error)
|
||||
UpdateDatasetDocument(ctx context.Context, userID, datasetID, documentID string, req *document.UpdateDatasetDocumentRequest, present map[string]bool) (*document.UpdateDatasetDocumentResponse, common.ErrorCode, error)
|
||||
BatchUpdateDocumentMetadatas(ctx context.Context, datasetID string, selector *document.DocumentMetadataSelector, updates []document.DocumentMetadataUpdate, deletes []document.DocumentMetadataDelete) (*document.BatchUpdateDocumentMetadatasResponse, common.ErrorCode, error)
|
||||
BatchUpdateDocumentMetadatas(ctx context.Context, datasetID string, selector *document.MetadataSelector, updates []document.MetadataUpdate, deletes []document.MetadataDelete) (*document.BatchUpdateMetadatasResponse, common.ErrorCode, error)
|
||||
ListIngestionTasks(ctx context.Context, userID string, datasetID *string, page, pageSize int) ([]*entity.IngestionTask, error)
|
||||
IngestDocuments(ctx context.Context, datasetID, userID string, docIDs []string) ([]*service.ParseDocumentResponse, error)
|
||||
StopIngestionTasks(ctx context.Context, tasks []string, userID string) ([]*entity.IngestionTask, error)
|
||||
@@ -1803,9 +1803,9 @@ func (h *DocumentHandler) UploadInfo(c *gin.Context) {
|
||||
}
|
||||
|
||||
type documentMetadataBatchRequest struct {
|
||||
Selector *document.DocumentMetadataSelector `json:"selector"`
|
||||
Updates []document.DocumentMetadataUpdate `json:"updates"`
|
||||
Deletes []document.DocumentMetadataDelete `json:"deletes"`
|
||||
Selector *document.MetadataSelector `json:"selector"`
|
||||
Updates []document.MetadataUpdate `json:"updates"`
|
||||
Deletes []document.MetadataDelete `json:"deletes"`
|
||||
}
|
||||
|
||||
func (h *DocumentHandler) MetadataBatchUpdate(c *gin.Context) {
|
||||
@@ -1887,15 +1887,15 @@ func inferJSONType(err error) string {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
func parseMetadataSelector(raw interface{}) (*document.DocumentMetadataSelector, string) {
|
||||
func parseMetadataSelector(raw interface{}) (*document.MetadataSelector, string) {
|
||||
if raw == nil {
|
||||
return &document.DocumentMetadataSelector{}, ""
|
||||
return &document.MetadataSelector{}, ""
|
||||
}
|
||||
m, ok := raw.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, "selector must be an object."
|
||||
}
|
||||
selector := &document.DocumentMetadataSelector{}
|
||||
selector := &document.MetadataSelector{}
|
||||
if v, ok := m["document_ids"]; ok && v != nil {
|
||||
ids, ok := v.([]interface{})
|
||||
if !ok {
|
||||
@@ -1915,15 +1915,15 @@ func parseMetadataSelector(raw interface{}) (*document.DocumentMetadataSelector,
|
||||
return selector, ""
|
||||
}
|
||||
|
||||
func parseMetadataUpdates(raw interface{}) ([]document.DocumentMetadataUpdate, string) {
|
||||
func parseMetadataUpdates(raw interface{}) ([]document.MetadataUpdate, string) {
|
||||
if raw == nil {
|
||||
return []document.DocumentMetadataUpdate{}, ""
|
||||
return []document.MetadataUpdate{}, ""
|
||||
}
|
||||
arr, ok := raw.([]interface{})
|
||||
if !ok {
|
||||
return nil, "updates and deletes must be lists."
|
||||
}
|
||||
updates := make([]document.DocumentMetadataUpdate, 0, len(arr))
|
||||
updates := make([]document.MetadataUpdate, 0, len(arr))
|
||||
for _, item := range arr {
|
||||
m, ok := item.(map[string]interface{})
|
||||
if !ok {
|
||||
@@ -1934,20 +1934,20 @@ func parseMetadataUpdates(raw interface{}) ([]document.DocumentMetadataUpdate, s
|
||||
return nil, "Each update requires key and value."
|
||||
}
|
||||
value := m["value"]
|
||||
updates = append(updates, document.DocumentMetadataUpdate{Key: key, Value: value})
|
||||
updates = append(updates, document.MetadataUpdate{Key: key, Value: value})
|
||||
}
|
||||
return updates, ""
|
||||
}
|
||||
|
||||
func parseMetadataDeletes(raw interface{}) ([]document.DocumentMetadataDelete, string) {
|
||||
func parseMetadataDeletes(raw interface{}) ([]document.MetadataDelete, string) {
|
||||
if raw == nil {
|
||||
return []document.DocumentMetadataDelete{}, ""
|
||||
return []document.MetadataDelete{}, ""
|
||||
}
|
||||
arr, ok := raw.([]interface{})
|
||||
if !ok {
|
||||
return nil, "updates and deletes must be lists."
|
||||
}
|
||||
deletes := make([]document.DocumentMetadataDelete, 0, len(arr))
|
||||
deletes := make([]document.MetadataDelete, 0, len(arr))
|
||||
for _, item := range arr {
|
||||
m, ok := item.(map[string]interface{})
|
||||
if !ok {
|
||||
@@ -1957,7 +1957,7 @@ func parseMetadataDeletes(raw interface{}) ([]document.DocumentMetadataDelete, s
|
||||
if key == "" {
|
||||
return nil, "Each delete requires key."
|
||||
}
|
||||
deletes = append(deletes, document.DocumentMetadataDelete{Key: key})
|
||||
deletes = append(deletes, document.MetadataDelete{Key: key})
|
||||
}
|
||||
return deletes, ""
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ const uploadTestDatasetID = "123e4567-e89b-12d3-a456-426614174000"
|
||||
func (f *fakeDocumentService) UpdateDatasetDocument(ctx context.Context, userID, datasetID, documentID string, req *document.UpdateDatasetDocumentRequest, present map[string]bool) (*document.UpdateDatasetDocumentResponse, common.ErrorCode, error) {
|
||||
return nil, common.CodeSuccess, nil
|
||||
}
|
||||
func (f *fakeDocumentService) BatchUpdateDocumentMetadatas(ctx context.Context, datasetID string, selector *document.DocumentMetadataSelector, updates []document.DocumentMetadataUpdate, deletes []document.DocumentMetadataDelete) (*document.BatchUpdateDocumentMetadatasResponse, common.ErrorCode, error) {
|
||||
func (f *fakeDocumentService) BatchUpdateDocumentMetadatas(ctx context.Context, datasetID string, selector *document.MetadataSelector, updates []document.MetadataUpdate, deletes []document.MetadataDelete) (*document.BatchUpdateMetadatasResponse, common.ErrorCode, error) {
|
||||
return nil, common.CodeSuccess, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -486,7 +486,7 @@ func (h *FileHandler) Download(c *gin.Context) {
|
||||
var blob []byte
|
||||
var getErr error
|
||||
if file.Location != nil && *file.Location != "" {
|
||||
blob, getErr = storageImpl.Get(file.ParentID, *file.Location)
|
||||
blob, getErr = storageImpl.Get(ctx, file.ParentID, *file.Location)
|
||||
}
|
||||
|
||||
// If blob is empty, try fallback via file2document
|
||||
@@ -497,7 +497,7 @@ func (h *FileHandler) Download(c *gin.Context) {
|
||||
common.ResponseWithCodeData(c, common.CodeServerError, nil, "Failed to get file storage address: "+err.Error())
|
||||
return
|
||||
}
|
||||
blob, getErr = storageImpl.Get(storageAddr.Bucket, storageAddr.Name)
|
||||
blob, getErr = storageImpl.Get(ctx, storageAddr.Bucket, storageAddr.Name)
|
||||
}
|
||||
|
||||
// Check if we got valid data
|
||||
|
||||
Reference in New Issue
Block a user