- 实现了抖音API请求失败时的自动重试逻辑,间隔100毫秒 - 添加了上下文取消支持,避免无限重试 - 将HTTP客户端改为全局变量,提升性能和连接复用 - 前端上传线程数限制从100调整为500 - 更新类型声明以符合最新Go语言规范
This commit is contained in:
@@ -200,7 +200,7 @@ try {
|
||||
|
||||
<div class="form-item">
|
||||
<label>单文件上传线程</label>
|
||||
<el-input-number v-model="uploadThreads" :min="1" :max="100" :disabled="isRunning"
|
||||
<el-input-number v-model="uploadThreads" :min="1" :max="500" :disabled="isRunning"
|
||||
@change="writeUploadThreads()"/>
|
||||
</div>
|
||||
|
||||
|
||||
+15
-2
@@ -64,7 +64,19 @@ func UploadDataToServer(ctx context.Context, data string) error {
|
||||
secUserId := strings.Split(data, "----")[1]
|
||||
hasVideo, err := CheckHasVideo(secUserId)
|
||||
if err != nil {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user