github.com/qjfoidnh/BaiduPCS-Go@v0.0.0-20231011165705-caa18a3765f3/internal/pcsfunctions/pcsupload/upload2.go (about) 1 package pcsupload 2 3 /* 4 import ( 5 "github.com/qjfoidnh/BaiduPCS-Go/baidupcs" 6 ) 7 8 type ( 9 // PCSUpload2 新的上传方式 10 // TODO 11 PCSUpload2 struct { 12 pcs *baidupcs.BaiduPCS 13 targetPath string 14 uploadid string 15 } 16 ) 17 18 func NewPCSUpload2(pcs *baidupcs.BaiduPCS, targetPath string) uploader.MultiUpload { 19 return &PCSUpload{ 20 pcs: pcs, 21 targetPath: targetPath, 22 } 23 } 24 25 func (pu2 *PCSUpload2) lazyInit() { 26 if pu2.pcs == nil { 27 pu2.pcs = &baidupcs.BaiduPCS{} 28 } 29 } 30 31 // Precreate 32 func (pu2 *PCSUpload2) Precreate() (err error) { 33 return nil 34 } 35 36 func (pu2 *PCSUpload2) TmpFile(ctx context.Context, partseq int, partOffset int64, r rio.ReaderLen64) (checksum string, uperr error) { 37 pu2.lazyInit() 38 return pu.pcs.UploadTmpFile(func(uploadURL string, jar http.CookieJar) (resp *http.Response, err error) { 39 client := pcsconfig.Config.HTTPClient() 40 client.SetCookiejar(jar) 41 client.SetTimeout(0) 42 43 mr := multipartreader.NewMultipartReader() 44 mr.AddFormFile("uploadedfile", "", r) 45 mr.CloseMultipart() 46 47 doneChan := make(chan struct{}, 1) 48 go func() { 49 resp, err = client.Req("POST", uploadURL, mr, nil) 50 doneChan <- struct{}{} 51 }() 52 select { 53 case <-ctx.Done(): 54 return resp, ctx.Err() 55 case <-doneChan: 56 // return 57 } 58 return 59 }) 60 } 61 62 func (pu2 *PCSUpload2) CreateSuperFile(checksumList ...string) (err error) { 63 return nil 64 } 65 */