refactor(api): 优化抖音API请求重试机制和客户端配置
构建上传工具 / build (push) Successful in 1m12s

- 实现了抖音API请求失败时的自动重试逻辑,间隔100毫秒
- 添加了上下文取消支持,避免无限重试
- 将HTTP客户端改为全局变量,提升性能和连接复用
- 前端上传线程数限制从100调整为500
- 更新类型声明以符合最新Go语言规范
This commit is contained in:
2026-07-27 00:41:14 +08:00
parent 8889e9ab55
commit 2c0207c45f
3 changed files with 18 additions and 5 deletions
+16 -3
View File
@@ -64,7 +64,19 @@ func UploadDataToServer(ctx context.Context, data string) error {
secUserId := strings.Split(data, "----")[1]
hasVideo, err := CheckHasVideo(secUserId)
if err != nil {
return err
for err != nil {
fmt.Println("抖音请求api重试")
//定时器定时100毫秒
ticker := time.NewTicker(100 * time.Millisecond)
select {
case <-ctx.Done():
return err
case <-ticker.C:
ticker.Stop()
hasVideo, err = CheckHasVideo(secUserId)
}
}
}
if hasVideo {
params.Set("token", config.APPConfig.HasVideoToken)
@@ -97,8 +109,9 @@ func UploadDataToServer(ctx context.Context, data string) error {
return err
}
var douYinClient = &http.Client{}
func CheckHasVideo(secUserId string) (bool, error) {
client := &http.Client{}
req, err := http.NewRequest(
"GET",
"https://imdesktop.douyin.com/aweme/v1/web/user/profile/other/?sec_user_id="+secUserId,
@@ -114,7 +127,7 @@ func CheckHasVideo(secUserId string) (bool, error) {
req.Header.Add("Host", "imdesktop.douyin.com")
req.Header.Add("Connection", "keep-alive")
res, err := client.Do(req)
res, err := douYinClient.Do(req)
if err != nil {
fmt.Println(err)
return false, err