MCPcopy Create free account
hub / github.com/LagrangeDev/LagrangeGo / UploadPrivateImage

Method UploadPrivateImage

client/richmedia.go:62–125  ·  view source on GitHub ↗
(targetUID string, image *message.ImageElement)

Source from the content-addressed store, hash-verified

60}
61
62func (c *QQClient) UploadPrivateImage(targetUID string, image *message.ImageElement) (*message.ImageElement, error) {
63 if image == nil || image.Stream == nil {
64 return nil, errors.New("image is nil")
65 }
66 defer utils.CloseIO(image.Stream)
67 image.IsGroup = false
68 req, err := oidb.BuildPrivateImageUploadReq(targetUID, image)
69 if err != nil {
70 return nil, err
71 }
72 resp, err := c.sendOidbPacketAndWait(req)
73 if err != nil {
74 return nil, err
75 }
76 uploadResp, err := oidb.ParsePrivateImageUploadResp(resp)
77 if err != nil {
78 return nil, err
79 }
80 ukey := uploadResp.Upload.UKey.Unwrap()
81 c.debugln("private image upload ukey:", ukey)
82 if ukey != "" {
83 index := uploadResp.Upload.MsgInfo.MsgInfoBody[0].Index
84 sha1hash, err := hex.DecodeString(index.Info.FileSha1)
85 if err != nil {
86 return nil, err
87 }
88 extend := &highway.NTV2RichMediaHighwayExt{
89 FileUuid: index.FileUuid,
90 UKey: ukey,
91 Network: &highway.NTHighwayNetwork{
92 IPv4S: oidbIPv4ToNTHighwayIPv4(uploadResp.Upload.IPv4S),
93 },
94 MsgInfoBody: uploadResp.Upload.MsgInfo.MsgInfoBody,
95 BlockSize: uint32(highway2.BlockSize),
96 Hash: &highway.NTHighwayHash{
97 FileSha1: [][]byte{sha1hash},
98 },
99 }
100 extStream, err := proto.Marshal(extend)
101 if err != nil {
102 return nil, err
103 }
104 md5hash, err := hex.DecodeString(index.Info.FileHash)
105 if err != nil {
106 return nil, err
107 }
108 err = c.highwayUpload(1003,
109 image.Stream, uint64(image.Size),
110 md5hash, extStream,
111 )
112 if err != nil {
113 return nil, err
114 }
115 }
116 image.MsgInfo = uploadResp.Upload.MsgInfo
117 image.FileUUID = uploadResp.Upload.MsgInfo.MsgInfoBody[0].Index.FileUuid
118 compatImage := &message2.NotOnlineImage{}
119 err = proto.Unmarshal(uploadResp.Upload.CompatQMsg, compatImage)

Callers 2

UploadImageMethod · 0.95

Calls 7

sendOidbPacketAndWaitMethod · 0.95
debuglnMethod · 0.95
highwayUploadMethod · 0.95
CloseIOFunction · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
oidbIPv4ToNTHighwayIPv4Function · 0.85

Tested by

no test coverage detected