From 50f0f572bceafdf2c87ad9fa241575c1f25ab6bf Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Mon, 11 Jan 2021 00:45:49 +0800 Subject: [PATCH] fix multi-threading upload. --- coolq/bot.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index de8cd7b..f8791e6 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -3,8 +3,11 @@ package coolq import ( "bytes" "encoding/gob" + "encoding/hex" "fmt" + "github.com/Mrs4s/MiraiGo/utils" "hash/crc32" + "io" "os" "path" "runtime/debug" @@ -132,10 +135,11 @@ func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message return nil, err } defer video.Close() - // todo 多线程上传失败: 短视频上传失败: resp is empty (upload video file error: upload failed: 70 - //hash, _ := utils.ComputeMd5AndLength(io.MultiReader(video, v.thumb)) - //cacheFile := path.Join(global.CACHE_PATH, hex.EncodeToString(hash[:])+".cache") - return bot.Client.UploadGroupShortVideo(target, video, v.thumb) + hash, _ := utils.ComputeMd5AndLength(io.MultiReader(video, v.thumb)) + cacheFile := path.Join(global.CACHE_PATH, hex.EncodeToString(hash[:])+".cache") + _, _ = video.Seek(0, io.SeekStart) + _, _ = v.thumb.Seek(0, io.SeekStart) + return bot.Client.UploadGroupShortVideo(target, video, v.thumb, cacheFile) } return &v.ShortVideoElement, nil }