1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

fix private image.

This commit is contained in:
Mrs4s 2021-01-09 03:24:29 +08:00
parent 29f670b720
commit bcedac03af
3 changed files with 9 additions and 14 deletions

View File

@ -2,7 +2,6 @@ package client
import ( import (
"bytes" "bytes"
"crypto/md5"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary"
@ -23,9 +22,9 @@ func init() {
} }
func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*message.GroupImageElement, error) { func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*message.GroupImageElement, error) {
h := md5.New() _, _ = img.Seek(0, io.SeekStart) // safe
length, _ := io.Copy(h, img) fh, length := utils.ComputeMd5AndLength(img)
fh := h.Sum(nil) _, _ = img.Seek(0, io.SeekStart)
seq, pkt := c.buildGroupImageStorePacket(groupCode, fh[:], int32(length)) seq, pkt := c.buildGroupImageStorePacket(groupCode, fh[:], int32(length))
r, err := c.sendAndWait(seq, pkt) r, err := c.sendAndWait(seq, pkt)
if err != nil { if err != nil {
@ -38,7 +37,6 @@ func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*messag
if rsp.IsExists { if rsp.IsExists {
goto ok goto ok
} }
_, _ = img.Seek(0, io.SeekStart)
if len(c.srvSsoAddrs) == 0 { if len(c.srvSsoAddrs) == 0 {
for i, addr := range rsp.UploadIp { for i, addr := range rsp.UploadIp {
c.srvSsoAddrs = append(c.srvSsoAddrs, fmt.Sprintf("%v:%v", binary.UInt32ToIPV4Address(uint32(addr)), rsp.UploadPort[i])) c.srvSsoAddrs = append(c.srvSsoAddrs, fmt.Sprintf("%v:%v", binary.UInt32ToIPV4Address(uint32(addr)), rsp.UploadPort[i]))
@ -66,9 +64,7 @@ func (c *QQClient) UploadGroupImageByFile(groupCode int64, path string) (*messag
if err != nil { if err != nil {
return nil, err return nil, err
} }
h := md5.New() fh, length := utils.ComputeMd5AndLength(img)
length, _ := io.Copy(h, img)
fh := h.Sum(nil)
seq, pkt := c.buildGroupImageStorePacket(groupCode, fh[:], int32(length)) seq, pkt := c.buildGroupImageStorePacket(groupCode, fh[:], int32(length))
r, err := c.sendAndWait(seq, pkt) r, err := c.sendAndWait(seq, pkt)
if err != nil { if err != nil {
@ -109,9 +105,8 @@ func (c *QQClient) UploadPrivateImage(target int64, img io.ReadSeeker) (*message
func (c *QQClient) uploadPrivateImage(target int64, img io.ReadSeeker, count int) (*message.FriendImageElement, error) { func (c *QQClient) uploadPrivateImage(target int64, img io.ReadSeeker, count int) (*message.FriendImageElement, error) {
count++ count++
h := md5.New() fh, length := utils.ComputeMd5AndLength(img)
length, _ := io.Copy(h, img) _, _ = img.Seek(0, io.SeekStart)
fh := h.Sum(nil)
e, err := c.QueryFriendImage(target, fh[:], int32(length)) e, err := c.QueryFriendImage(target, fh[:], int32(length))
if errors.Is(err, ErrNotExists) { if errors.Is(err, ErrNotExists) {
// use group highway upload and query again for image id. // use group highway upload and query again for image id.

View File

@ -92,8 +92,8 @@ ok:
// UploadGroupShortVideo 将视频和封面上传到服务器, 返回 message.ShortVideoElement 可直接发送 // UploadGroupShortVideo 将视频和封面上传到服务器, 返回 message.ShortVideoElement 可直接发送
// combinedCache 本地文件缓存, 设置后可多线程上传 // combinedCache 本地文件缓存, 设置后可多线程上传
func (c *QQClient) UploadGroupShortVideo(groupCode int64, video, thumb io.ReadSeeker, combinedCache ...string) (*message.ShortVideoElement, error) { func (c *QQClient) UploadGroupShortVideo(groupCode int64, video, thumb io.ReadSeeker, combinedCache ...string) (*message.ShortVideoElement, error) {
videoHash, videoLen := utils.GetMd5AndLength(video) videoHash, videoLen := utils.ComputeMd5AndLength(video)
thumbHash, thumbLen := utils.GetMd5AndLength(thumb) thumbHash, thumbLen := utils.ComputeMd5AndLength(thumb)
cache := "" cache := ""
if len(combinedCache) > 0 { if len(combinedCache) > 0 {
cache = combinedCache[0] cache = combinedCache[0]

View File

@ -24,7 +24,7 @@ func IsChanClosed(ch interface{}) bool {
return *(*uint32)(unsafe.Pointer(ptr)) > 0 return *(*uint32)(unsafe.Pointer(ptr)) > 0
} }
func GetMd5AndLength(r io.Reader) ([]byte, int64) { func ComputeMd5AndLength(r io.Reader) ([]byte, int64) {
h := md5.New() h := md5.New()
length, _ := io.Copy(h, r) length, _ := io.Copy(h, r)
fh := h.Sum(nil) fh := h.Sum(nil)