NewClientFromURL creates a client from a full base URL (e.g., "https://app.getpad.dev").
(baseURL string)
| 38 | |
| 39 | // NewClientFromURL creates a client from a full base URL (e.g., "https://app.getpad.dev"). |
| 40 | func NewClientFromURL(baseURL string) *Client { |
| 41 | baseURL = strings.TrimRight(baseURL, "/") |
| 42 | c := &Client{ |
| 43 | baseURL: baseURL + "/api/v1", |
| 44 | httpClient: &http.Client{ |
| 45 | Timeout: 10 * time.Second, |
| 46 | }, |
| 47 | // Long-running transfer client for streaming endpoints |
| 48 | // (workspace export bundles in/out, future S3 downloads). |
| 49 | // 10s on the default client is the right SLA for normal API |
| 50 | // calls but kills a multi-GiB bundle upload mid-stream over |
| 51 | // anything but a fast local link. 1 hour is generous enough |
| 52 | // for ~100 MB/s uplinks shipping a 350 GiB bundle and still |
| 53 | // caps a hung connection eventually. (Codex review on PR |
| 54 | // #306 round 2.) |
| 55 | streamClient: &http.Client{ |
| 56 | Timeout: 1 * time.Hour, |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | // Auto-load credentials for THIS server URL if any are saved. We use |
| 61 | // the original baseURL (without the /api/v1 suffix added below) so |
| 62 | // the lookup matches what login/save commands key on. Credentials |
| 63 | // for other servers are left untouched in the store — see TASK-1228 |
| 64 | // / IDEA-1226 for the per-server design. |
| 65 | if store, err := LoadStore(); err == nil { |
| 66 | if creds := store.Get(baseURL); creds != nil { |
| 67 | c.authToken = creds.Token |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // Auto-load agent name from .pad.toml if available |
| 72 | if pt, _ := LoadPadToml(); pt != nil && pt.AgentName != "" { |
| 73 | c.agentName = pt.AgentName |
| 74 | } |
| 75 | |
| 76 | return c |
| 77 | } |
| 78 | |
| 79 | // SetAuthToken sets the authorization token for API requests. |
| 80 | func (c *Client) SetAuthToken(token string) { |