feat(providers): route only the generate submit through the proxy

Extends the adobe split to leonardo, krea, imagine, runway (image+video) and chatgpt: reference-image upload, polling and result download egress on the local IP; only the generate/task-create submit uses proxy.url. chatgpt keeps its anti-bot-guarded submit+upload phase on the proxy and moves only the existing second (poll/resolve/download) session to local. custom is already direct. Build+vet pass; adobe verified live, the other providers are code-complete but not yet live-tested (no dev accounts).
This commit is contained in:
2026-07-09 16:21:31 +08:00
parent db3219416e
commit 6c2a942a88
10 changed files with 109 additions and 39 deletions
+14 -3
View File
@@ -337,7 +337,12 @@ func (c *Client) FetchCreditsBalance(ctx context.Context, cred string) (map[stri
// ---------------------------------------------------------------------------
func (c *Client) apiGet(ctx context.Context, token, url string) ([]byte, int, error) {
client, err := c.newTLSClient()
return c.apiGetP(ctx, token, url, true)
}
// apiGetP picks the egress: polling runs direct (local IP).
func (c *Client) apiGetP(ctx context.Context, token, url string, useProxy bool) ([]byte, int, error) {
client, err := c.newTLSClientP(useProxy)
if err != nil {
return nil, 0, err
}
@@ -365,12 +370,18 @@ func (c *Client) apiGet(ctx context.Context, token, url string) ([]byte, int, er
return b, resp.StatusCode, err
}
func (c *Client) newTLSClient() (tlsclient.HttpClient, error) {
func (c *Client) newTLSClient() (tlsclient.HttpClient, error) { return c.newTLSClientP(true) }
// newDirectTLSClient egresses on the local IP (never the proxy). Used for
// polling and result download.
func (c *Client) newDirectTLSClient() (tlsclient.HttpClient, error) { return c.newTLSClientP(false) }
func (c *Client) newTLSClientP(useProxy bool) (tlsclient.HttpClient, error) {
options := []tlsclient.HttpClientOption{
tlsclient.WithTimeoutSeconds(60),
tlsclient.WithClientProfile(profiles.Chrome_120),
}
if c.proxy != "" {
if useProxy && c.proxy != "" {
options = append(options, tlsclient.WithProxyUrl(c.proxy))
}
return tlsclient.NewHttpClient(tlsclient.NewNoopLogger(), options...)
+2 -2
View File
@@ -101,7 +101,7 @@ func (c *Client) pollImage(ctx context.Context, token, userID, batchID string) (
url := teamsBase + "/v1/org/" + userID + "/objects?batch=true&limit=50&service=image,chat-image"
for {
body, status, err := c.apiGet(ctx, token, url)
body, status, err := c.apiGetP(ctx, token, url, false)
if err == nil && status == 200 {
var resp struct {
Data []struct {
@@ -181,7 +181,7 @@ func firstImageURL(raw string) string {
}
func (c *Client) download(ctx context.Context, url string) ([]byte, error) {
client, err := c.newTLSClient()
client, err := c.newDirectTLSClient()
if err != nil {
return nil, err
}