fix installer script
Some checks failed
CI / test-build (push) Failing after 2m14s

This commit is contained in:
2025-12-15 01:55:39 +07:00
parent c405ca27dd
commit f45c878051
3 changed files with 798 additions and 18 deletions

View File

@@ -31,8 +31,8 @@ func (c *APIClient) SetToken(token string) {
c.token = token
}
// Login authenticates with the API
func (c *APIClient) Login(username, password string) (string, error) {
// Login authenticates with the API and returns user info
func (c *APIClient) Login(username, password string) (string, map[string]interface{}, error) {
reqBody := map[string]string{
"username": username,
"password": password,
@@ -40,39 +40,46 @@ func (c *APIClient) Login(username, password string) (string, error) {
body, err := json.Marshal(reqBody)
if err != nil {
return "", err
return "", nil, err
}
req, err := http.NewRequest("POST", c.baseURL+"/api/v1/auth/login", bytes.NewReader(body))
if err != nil {
return "", err
return "", nil, err
}
req.Header.Set("Content-Type", "application/json")
resp, err := c.httpClient.Do(req)
if err != nil {
return "", fmt.Errorf("request failed: %w", err)
return "", nil, fmt.Errorf("request failed: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return "", fmt.Errorf("login failed: %s", string(body))
return "", nil, fmt.Errorf("login failed: %s", string(body))
}
var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return "", err
return "", nil, err
}
token, ok := result["token"].(string)
if !ok {
return "", fmt.Errorf("no token in response")
return "", nil, fmt.Errorf("no token in response")
}
c.SetToken(token)
return token, nil
// Extract user info if available
var user map[string]interface{}
if u, ok := result["user"].(map[string]interface{}); ok {
user = u
}
return token, user, nil
}
// Get performs a GET request
@@ -163,3 +170,38 @@ func (c *APIClient) Delete(path string) error {
return nil
}
// Put performs a PUT request
func (c *APIClient) Put(path string, data interface{}) ([]byte, error) {
body, err := json.Marshal(data)
if err != nil {
return nil, err
}
req, err := http.NewRequest("PUT", c.baseURL+path, bytes.NewReader(body))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
if c.token != "" {
req.Header.Set("Authorization", "Bearer "+c.token)
}
resp, err := c.httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("request failed: %w", err)
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode >= 400 {
return nil, fmt.Errorf("API error (status %d): %s", resp.StatusCode, string(respBody))
}
return respBody, nil
}