mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-24 17:36:47 +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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user