mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-12 03:33:33 +08:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user