From 3430b57cbf3245414a027484741127139860c6f5 Mon Sep 17 00:00:00 2001 From: kyx236 Date: Fri, 30 Jan 2026 13:19:28 +0800 Subject: [PATCH] feat: add API endpoint for uploading and validating team owner accounts with concurrent account ID fetching and database storage. --- backend/internal/api/upload.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/internal/api/upload.go b/backend/internal/api/upload.go index 541013c..1f79bba 100644 --- a/backend/internal/api/upload.go +++ b/backend/internal/api/upload.go @@ -10,6 +10,7 @@ import ( "unicode" "codex-pool/internal/client" + "codex-pool/internal/config" "codex-pool/internal/database" "codex-pool/internal/logger" ) @@ -255,7 +256,13 @@ func normalizeOwner(rec accountRecord, index int) (database.TeamOwner, error) { // fetchAccountID 通过 token 获取 account_id func fetchAccountID(token string) (string, error) { - tlsClient, err := client.New("") + // 使用配置中的代理(如果启用) + proxy := "" + if cfg := config.Get(); cfg != nil { + proxy = cfg.GetProxy() + } + + tlsClient, err := client.New(proxy) if err != nil { return "", fmt.Errorf("创建 TLS 客户端失败: %v", err) } @@ -274,15 +281,15 @@ func fetchAccountID(token string) (string, error) { } defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { - return "", fmt.Errorf("API 返回状态码: %d", resp.StatusCode) - } - - body, err := client.ReadBody(resp) + body, err := io.ReadAll(resp.Body) if err != nil { return "", fmt.Errorf("读取响应失败: %v", err) } + if resp.StatusCode != http.StatusOK { + return "", fmt.Errorf("API 返回状态码: %d, 响应: %s", resp.StatusCode, string(body)[:min(200, len(body))]) + } + // 解析响应 var result struct { Accounts map[string]struct {