@@ -16,32 +16,42 @@ import (
1616func DownloadAccounts (resp * TopupResponse , accountsDir string , httpClient * http.Client ) ([]account.Account , error ) {
1717 var newAccounts []account.Account
1818
19- for _ , accInfo := range resp .Accounts {
20- logger .Info ("处理账号:%s" , accInfo .FileName )
19+ logger .Debug ("开始下载账号:总数=%d" , len (resp .Accounts ))
20+
21+ for i , accInfo := range resp .Accounts {
22+ logger .Info ("处理账号 %d/%d:%s" , i + 1 , len (resp .Accounts ), accInfo .FileName )
23+ logger .Debug ("账号信息: download_url=%s, auth_json_len=%d" ,
24+ accInfo .DownloadURL , len (accInfo .AuthJSON ))
2125
2226 var acc account.Account
2327
2428 // Try to use auth_json first
2529 if len (accInfo .AuthJSON ) > 0 {
30+ logger .Debug ("使用 auth_json 解析账号" )
2631 if err := json .Unmarshal (accInfo .AuthJSON , & acc ); err != nil {
2732 logger .Warn ("解析 %s 的 auth_json 失败:%v" , accInfo .FileName , err )
33+ logger .Debug ("auth_json 内容: %s" , string (accInfo .AuthJSON ))
2834 continue
2935 }
36+ logger .Debug ("auth_json 解析成功: account_id=%s, email=%s" , acc .AccountID , acc .Email )
3037 } else if accInfo .DownloadURL != "" {
3138 // Download from URL
39+ logger .Debug ("从 URL 下载账号: %s" , accInfo .DownloadURL )
3240 var err error
3341 acc , err = downloadFromURL (accInfo .DownloadURL , httpClient )
3442 if err != nil {
3543 logger .Warn ("从 %s 下载账号失败:%v" , accInfo .DownloadURL , err )
3644 continue
3745 }
46+ logger .Debug ("URL 下载成功: account_id=%s, email=%s" , acc .AccountID , acc .Email )
3847 } else {
3948 logger .Warn ("%s 没有 auth_json 或 download_url" , accInfo .FileName )
4049 continue
4150 }
4251
4352 // Set file path
4453 acc .FilePath = filepath .Join (accountsDir , accInfo .FileName )
54+ logger .Debug ("设置文件路径: %s" , acc .FilePath )
4555
4656 // Save account
4757 storage := account .NewStorage (accountsDir )
@@ -54,18 +64,24 @@ func DownloadAccounts(resp *TopupResponse, accountsDir string, httpClient *http.
5464 newAccounts = append (newAccounts , acc )
5565 }
5666
67+ logger .Debug ("下载完成:成功=%d, 失败=%d" , len (newAccounts ), len (resp .Accounts )- len (newAccounts ))
68+
5769 return newAccounts , nil
5870}
5971
6072func downloadFromURL (url string , httpClient * http.Client ) (account.Account , error ) {
6173 var acc account.Account
6274
75+ logger .Debug ("开始从 URL 下载: %s" , url )
76+
6377 resp , err := httpClient .Get (url )
6478 if err != nil {
6579 return acc , fmt .Errorf ("failed to download: %w" , err )
6680 }
6781 defer resp .Body .Close ()
6882
83+ logger .Debug ("下载响应状态码: %d" , resp .StatusCode )
84+
6985 if resp .StatusCode != http .StatusOK {
7086 return acc , fmt .Errorf ("download failed with status %d" , resp .StatusCode )
7187 }
@@ -75,7 +91,10 @@ func downloadFromURL(url string, httpClient *http.Client) (account.Account, erro
7591 return acc , fmt .Errorf ("failed to read response: %w" , err )
7692 }
7793
94+ logger .Debug ("下载响应体长度: %d bytes" , len (body ))
95+
7896 if err := json .Unmarshal (body , & acc ); err != nil {
97+ logger .Debug ("解析失败的 JSON: %s" , string (body ))
7998 return acc , fmt .Errorf ("failed to parse account JSON: %w" , err )
8099 }
81100
0 commit comments