mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-04 18:45:38 +08:00
Go CLI: fix list dataset files by dataset name (#16341)
### What problem does this PR solve? ``` RAGFlow(api/default)> list dataset 'ccc' files; Total: 1 ``` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -301,6 +301,8 @@ func (c *CLI) ExecuteUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
return c.APIListDatasetsCommand(cmd)
|
||||
case "api_list_dataset_documents":
|
||||
return c.APIListDatasetDocumentsCommand(cmd)
|
||||
case "api_list_dataset_files":
|
||||
return c.APIListDatasetFilesCommand(cmd)
|
||||
case "api_list_agents":
|
||||
return c.APIListAgentsCommand(cmd)
|
||||
case "api_list_chats":
|
||||
|
||||
@@ -1583,3 +1583,17 @@ func (c *CLI) UseAdminServer(cmd *Command) (ResponseIf, error) {
|
||||
result.Duration = 0
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *CLI) getDatasetIDByName(datasetName string) (string, error) {
|
||||
response, err := c.APIListDatasetsCommand(nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
commonResponse := response.(*CommonResponse)
|
||||
for _, dataset := range commonResponse.Data {
|
||||
if dataset["name"] == datasetName {
|
||||
return dataset["id"].(string), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("dataset %s not found", datasetName)
|
||||
}
|
||||
|
||||
@@ -336,12 +336,6 @@ func (c *CLI) APIListDatasetsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("this command is only allowed in USER mode")
|
||||
}
|
||||
|
||||
// Check for benchmark iterations
|
||||
iterations := 1
|
||||
if val, ok := cmd.Params["iterations"].(int); ok && val > 1 {
|
||||
iterations = val
|
||||
}
|
||||
|
||||
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
|
||||
|
||||
// Determine auth kind based on whether API key is being used
|
||||
@@ -358,11 +352,6 @@ func (c *CLI) APIListDatasetsCommand(cmd *Command) (ResponseIf, error) {
|
||||
authKind = "web"
|
||||
}
|
||||
|
||||
if iterations > 1 {
|
||||
// Benchmark mode - return raw result for benchmark stats
|
||||
return httpClient.RequestWithIterations("GET", "/datasets", authKind, nil, nil, iterations)
|
||||
}
|
||||
|
||||
// Normal mode
|
||||
resp, err := httpClient.Request("GET", "/datasets", authKind, nil, nil)
|
||||
if err != nil {
|
||||
@@ -431,6 +420,52 @@ func (c *CLI) APIListDatasetDocumentsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *CLI) APIListDatasetFilesCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != APIMode {
|
||||
return nil, fmt.Errorf("this command is only allowed in USER mode")
|
||||
}
|
||||
|
||||
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
|
||||
// Determine auth kind based on whether API key is being used
|
||||
if httpClient.LoginToken == nil && !httpClient.useAPIKey {
|
||||
return nil, fmt.Errorf("no authorization")
|
||||
}
|
||||
|
||||
datasetName, ok := cmd.Params["dataset_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no dataset name")
|
||||
}
|
||||
|
||||
datasetID, err := c.getDatasetIDByName(datasetName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get dataset id: %w", err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("/datasets/%s/documents", datasetID)
|
||||
|
||||
// Normal mode
|
||||
resp, err := httpClient.Request("GET", url, "web", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list documents: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list documents: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result ListDocumentsResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list documents failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// APIListAgentsCommand lists agents
|
||||
func (c *CLI) APIListAgentsCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != APIMode {
|
||||
|
||||
@@ -483,7 +483,6 @@ func (h *DocumentHandler) BatchUpdateDocumentStatus(c *gin.Context) {
|
||||
}
|
||||
|
||||
// ListDocuments document list
|
||||
|
||||
func (h *DocumentHandler) ListDocuments(c *gin.Context) {
|
||||
|
||||
datasetID := c.Param("dataset_id")
|
||||
|
||||
Reference in New Issue
Block a user