Go: refactor CLI (#15898)

### What problem does this PR solve?

1. remove unused code
2. fix login issue

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [x] Refactoring

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-06-10 16:06:30 +08:00
committed by GitHub
parent 357cb84cd4
commit 139f4515e8
5 changed files with 97 additions and 318 deletions

View File

@@ -23,6 +23,7 @@ import (
"fmt"
"io"
"net/http"
ce "ragflow/internal/cli/filesystem"
"time"
)
@@ -364,3 +365,46 @@ func (c *HTTPClient) RequestStream(method, path string, authKind string, headers
return resp.Body, nil
}
// PasswordPromptFunc is a function type for password input
type PasswordPromptFunc func(prompt string) (string, error)
// CurrentModel holds the current model configuration
type CurrentModel struct {
Provider string
Instance string
Model string
}
// httpClientAdapter adapts HTTPClient to ce.HTTPClientInterface
type httpClientAdapter struct {
client *HTTPClient
}
func (a *httpClientAdapter) Request(method, path string, authKind string, headers map[string]string, jsonBody map[string]interface{}) (*ce.HTTPResponse, error) {
// Auto-detect auth kind based on available tokens
// If authKind is "auto" or empty, determine based on token availability
if authKind == "auto" || authKind == "" {
if a.client.useAPIToken && a.client.APIToken != nil {
authKind = "api"
} else if a.client.LoginToken != nil {
authKind = "web"
} else {
authKind = "web" // default
}
}
resp, err := a.client.Request(method, path, authKind, headers, jsonBody)
if err != nil {
return nil, err
}
return &ce.HTTPResponse{
StatusCode: resp.StatusCode,
Body: resp.Body,
Headers: resp.Headers,
Duration: resp.Duration,
}, nil
}
func (a *httpClientAdapter) UploadMultipart(path string, contentType string, body io.Reader) error {
return a.client.UploadMultipart(path, contentType, body)
}