1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

try to fix image upload.

This commit is contained in:
Mrs4s 2020-08-22 02:23:24 +08:00
parent fe8e98b9d8
commit 7654a7a2a1
2 changed files with 23 additions and 24 deletions

View File

@ -552,7 +552,7 @@ func (c *QQClient) buildGroupImageStorePacket(groupCode int64, md5 []byte, size
func (c *QQClient) buildImageUploadPacket(data, updKey []byte, commandId int32, fmd5 [16]byte) (r [][]byte) {
offset := 0
binary.ToChunkedBytesF(data, 8192*1024, func(chunked []byte) {
binary.ToChunkedBytesF(data, 8192*8, func(chunked []byte) {
w := binary.NewWriter()
cmd5 := md5.Sum(chunked)
head, _ := proto.Marshal(&pb.ReqDataHighwayHead{

View File

@ -8,10 +8,9 @@ import (
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
"net"
"strconv"
"time"
)
func (c *QQClient) highwayUploadImage(ip uint32, port int, updKey, img []byte, cmdId int32) error {
@ -25,32 +24,32 @@ func (c *QQClient) highwayUploadImage(ip uint32, port int, updKey, img []byte, c
return err
}
defer conn.Close()
if err = conn.SetDeadline(time.Now().Add(time.Second * 10)); err != nil {
return err
}
h := md5.Sum(img)
pkt := c.buildImageUploadPacket(img, updKey, cmdId, h)
r := binary.NewNetworkReader(conn)
for _, p := range pkt {
_, err = conn.Write(p)
if err != nil {
return err
}
_, err = r.ReadByte()
if err != nil {
return err
}
hl, _ := r.ReadInt32()
a2, _ := r.ReadInt32()
payload, _ := r.ReadBytes(int(hl))
_, _ = r.ReadBytes(int(a2))
r.ReadByte()
rsp := new(pb.RspDataHighwayHead)
if err = proto.Unmarshal(payload, rsp); err != nil {
return err
}
if rsp.ErrorCode != 0 {
return errors.New("upload failed")
}
}
if err != nil {
return err
}
r := binary.NewNetworkReader(conn)
_, err = r.ReadByte()
if err != nil {
return err
}
hl, _ := r.ReadInt32()
_, _ = r.ReadBytes(4)
payload, _ := r.ReadBytes(int(hl))
rsp := new(pb.RspDataHighwayHead)
if err = proto.Unmarshal(payload, rsp); err != nil {
return err
}
if rsp.ErrorCode != 0 {
return errors.New("upload failed")
}
return nil
}