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

Method getGroupAlbumUploadSession

client/album.go:230–265  ·  view source on GitHub ↗
(param *uploadSessionParam)

Source from the content-addressed store, hash-verified

228}
229
230func (c *QQClient) getGroupAlbumUploadSession(param *uploadSessionParam) (*uploadOptions, int64, error) {
231 reqBody, timeStamp, err := c.buildUploadSessionReq(param)
232 if err != nil {
233 return nil, timeStamp, err
234 }
235 reqBodyData, err := json.Marshal(reqBody)
236 if err != nil {
237 return nil, timeStamp, err
238 }
239 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
240 defer cancel()
241 req, err := http.NewRequestWithContext(ctx, http.MethodPost,
242 fmt.Sprintf("https://h5.qzone.qq.com/webapp/json/sliceUpload/FileBatchControl/%x?g_tk=%d", param.CheckSum, param.GTK),
243 bytes.NewReader(reqBodyData))
244 if err != nil {
245 return nil, timeStamp, err
246 }
247 req.Header.Set("Content-Type", "application/json")
248 resp, err := c.SendRequestWithCookie(req)
249 if err != nil {
250 return nil, timeStamp, err
251 }
252 respData, err := io.ReadAll(resp.Body)
253 _ = resp.Body.Close()
254 if err != nil {
255 return nil, timeStamp, err
256 }
257 respJSON := gjson.ParseBytes(respData)
258 if respJSON.Get("ret").Int() != 0 {
259 return nil, timeStamp, fmt.Errorf("error: ret:%d, msg:%s", respJSON.Get("ret").Int(), respJSON.Get("msg").Str)
260 }
261 return &uploadOptions{
262 Session: respJSON.Get("data.session").Str,
263 BlockSize: int(respJSON.Get("data.slice_size").Int()),
264 }, timeStamp, nil
265}
266
267func (c *QQClient) uploadGroupAlbumBlock(typ uploadTypeParam, session string, seq, offset, chunkSize, totalSize, gtk int, chunk []byte, latest bool) (rsp *uploadBlockRsp, err error) {
268 uploadURLCmd := utils.Ternary[string](typ.ResourceType == ResourceTypeVideo, "FileUploadVideo", "FileUpload")

Callers 2

UploadGroupAlbumPhotoMethod · 0.95
UploadGroupAlbumVideoMethod · 0.95

Calls 5

buildUploadSessionReqMethod · 0.95
SendRequestWithCookieMethod · 0.95
ReadAllMethod · 0.80
MarshalMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected