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

Method UploadGroupImage

client/richmedia.go:127–185  ·  view source on GitHub ↗
(groupUin uint32, image *message.ImageElement)

Source from the content-addressed store, hash-verified

125}
126
127func (c *QQClient) UploadGroupImage(groupUin uint32, image *message.ImageElement) (*message.ImageElement, error) {
128 if image == nil || image.Stream == nil {
129 return nil, errors.New("element type is not group image")
130 }
131 defer utils.CloseIO(image.Stream)
132 image.IsGroup = true
133 req, err := oidb.BuildGroupImageUploadReq(groupUin, image)
134 if err != nil {
135 return nil, err
136 }
137 resp, err := c.sendOidbPacketAndWait(req)
138 if err != nil {
139 return nil, err
140 }
141 uploadResp, err := oidb.ParseGroupImageUploadResp(resp)
142 if err != nil {
143 return nil, err
144 }
145 ukey := uploadResp.Upload.UKey.Unwrap()
146 c.debugln("group image upload ukey:", ukey)
147 if ukey != "" {
148 index := uploadResp.Upload.MsgInfo.MsgInfoBody[0].Index
149 sha1hash, err := hex.DecodeString(index.Info.FileSha1)
150 if err != nil {
151 return nil, err
152 }
153 extend := &highway.NTV2RichMediaHighwayExt{
154 FileUuid: index.FileUuid,
155 UKey: ukey,
156 Network: &highway.NTHighwayNetwork{
157 IPv4S: oidbIPv4ToNTHighwayIPv4(uploadResp.Upload.IPv4S),
158 },
159 MsgInfoBody: uploadResp.Upload.MsgInfo.MsgInfoBody,
160 BlockSize: uint32(highway2.BlockSize),
161 Hash: &highway.NTHighwayHash{
162 FileSha1: [][]byte{sha1hash},
163 },
164 }
165 extStream, err := proto.Marshal(extend)
166 if err != nil {
167 return nil, err
168 }
169 md5hash, err := hex.DecodeString(index.Info.FileHash)
170 if err != nil {
171 return nil, err
172 }
173 err = c.highwayUpload(1004,
174 image.Stream, uint64(image.Size),
175 md5hash, extStream,
176 )
177 if err != nil {
178 return nil, err
179 }
180 }
181 image.MsgInfo = uploadResp.Upload.MsgInfo
182 image.FileUUID = uploadResp.Upload.MsgInfo.MsgInfoBody[0].Index.FileUuid
183 _ = proto.Unmarshal(uploadResp.Upload.CompatQMsg, image.CompatFace)
184 return image, nil

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