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

Method UploadPrivateVideo

client/richmedia.go:299–391  ·  view source on GitHub ↗
(targetUID string, video *message.ShortVideoElement)

Source from the content-addressed store, hash-verified

297}
298
299func (c *QQClient) UploadPrivateVideo(targetUID string, video *message.ShortVideoElement) (*message.ShortVideoElement, error) {
300 if video == nil || video.Stream == nil {
301 return nil, errors.New("video is nil")
302 }
303 if video.Thumb == nil || video.Thumb.Stream == nil {
304 return nil, errors.New("video thumb is nil")
305 }
306 defer utils.CloseIO(video.Stream)
307 defer utils.CloseIO(video.Thumb.Stream)
308 req, err := oidb.BuildPrivateVideoUploadReq(targetUID, video)
309 if err != nil {
310 return nil, err
311 }
312 resp, err := c.sendOidbPacketAndWait(req)
313 if err != nil {
314 return nil, err
315 }
316 uploadResp, err := oidb.ParsePrivateVideoUploadResp(resp)
317 if err != nil {
318 return nil, err
319 }
320 ukey := uploadResp.Upload.UKey.Unwrap()
321 // video
322 if ukey != "" {
323 index := uploadResp.Upload.MsgInfo.MsgInfoBody[0].Index
324 extend := &highway.NTV2RichMediaHighwayExt{
325 FileUuid: index.FileUuid,
326 UKey: ukey,
327 Network: &highway.NTHighwayNetwork{
328 IPv4S: oidbIPv4ToNTHighwayIPv4(uploadResp.Upload.IPv4S),
329 },
330 MsgInfoBody: uploadResp.Upload.MsgInfo.MsgInfoBody,
331 BlockSize: uint32(highway2.BlockSize),
332 Hash: &highway.NTHighwayHash{
333 FileSha1: crypto.ComputeBlockSha1(video.Stream, highway2.BlockSize),
334 },
335 }
336 extStream, err := proto.Marshal(extend)
337 if err != nil {
338 return nil, err
339 }
340 md5, err := hex.DecodeString(index.Info.FileHash)
341 if err != nil {
342 return nil, err
343 }
344 err = c.highwayUpload(1001, video.Stream, uint64(video.Size), md5, extStream)
345 if err != nil {
346 return nil, err
347
348 }
349 }
350 // thumb
351 subFile := uploadResp.Upload.SubFileInfos[0]
352 if subFile.UKey != "" {
353 index := uploadResp.Upload.MsgInfo.MsgInfoBody[1].Index
354 sha1, err := hex.DecodeString(index.Info.FileSha1)
355 if err != nil {
356 return nil, err

Callers 2

UploadShortVideoMethod · 0.95

Calls 7

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

Tested by

no test coverage detected