mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-07 03:48:44 +08:00
Go CLI: fix show variable (#16370)
### What problem does this PR solve? ``` RAGFlow(api/default)> show var 'mail.port'; +-----------+-----------+--------------+-------+ | data_type | name | setting_type | value | +-----------+-----------+--------------+-------+ | integer | mail.port | config | 30 | +-----------+-----------+--------------+-------+ ``` ### 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:
@@ -1146,6 +1146,51 @@ func (c *CLI) APISetVariableCommand(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// APIShowVariableCommand displays variable value
|
||||
func (c *CLI) APIShowVariableCommand(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]
|
||||
|
||||
if httpClient.APIKey == nil && httpClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("API key not set. Please login first")
|
||||
}
|
||||
|
||||
varName, ok := cmd.Params["var_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("var_name not provided")
|
||||
}
|
||||
|
||||
EncodedVarName := common.EncodeToBase64(varName)
|
||||
|
||||
endPoint := fmt.Sprintf("/system/variables/%s", EncodedVarName)
|
||||
|
||||
resp, err := httpClient.Request("GET", endPoint, "web", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get variable: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to get variable: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("show variable failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
normalizeVariableRows(result.Data)
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// APIShowAPIKeyCommand displays the current API key
|
||||
func (c *CLI) APIShowAPIKeyCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != APIMode {
|
||||
|
||||
Reference in New Issue
Block a user