Skip to content

Commit 56f9206

Browse files
committed
增加baidu_youth秒存功能
1 parent c3cffe0 commit 56f9206

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

backend/baidu_youth/api/api.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,25 @@ func (b *BaiduApi) Create(path string, preCreateFileData *PreCreateFileData, upl
317317
}
318318
return opts, nil
319319
}
320+
321+
func (b *BaiduApi) Rapid(path string, contentMd5 string, sliceMd5 string, size int64) (opts *rest.Opts, err error) {
322+
data := url.Values{}
323+
data.Add("path", FixToBaiduPath(path))
324+
data.Add("content-length", strconv.FormatInt(size, 10))
325+
data.Add("content-md5", contentMd5)
326+
data.Add("slice-md5", sliceMd5)
327+
data.Add("rtype", "1")
328+
data.Add("ondup", "newcopy")
329+
330+
opts = &rest.Opts{
331+
Method: "POST",
332+
RootURL: "https://d.pcs.baidu.com/rest/2.0/pcs/file",
333+
Parameters: url.Values{
334+
"method": []string{"rapidupload"},
335+
//"app_id": []string{"25179614"},
336+
},
337+
ContentType: "application/x-www-form-urlencoded",
338+
Body: strings.NewReader(data.Encode()),
339+
}
340+
return opts, nil
341+
}

backend/baidu_youth/api/types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ type CreateVO struct {
138138
BaseItem
139139
}
140140

141+
type PcsBaseBaiduResponse struct {
142+
ErrnoCode int `json:"error_code"`
143+
ErrorMsg int `json:"error_msg"`
144+
RequestId int64 `json:"request_id"`
145+
}
146+
147+
func (b PcsBaseBaiduResponse) GetErrno() int {
148+
return b.ErrnoCode
149+
}
150+
151+
type RapidVO struct {
152+
BaseBaiduResponse
153+
BaseItem
154+
}
155+
141156
type QuotaInfoResponse struct {
142157
BaseBaiduResponse
143158
Total int64 `json:"total"`

backend/baidu_youth/compat_fs.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,3 +644,24 @@ func (f *Fs) GetQuotaInfo(ctx context.Context) (*api.QuotaInfoResponse, error) {
644644
}
645645
return info, nil
646646
}
647+
648+
// Rapid fs.ErrorFileRapidUpload
649+
func (f *Fs) Rapid(ctx context.Context, path string, contentMd5 string, sliceMd5 string, size int64) (baseItem *api.BaseItem, success bool, err error) {
650+
info := new(api.RapidVO)
651+
err = f.pacer.Call(func() (bool, error) {
652+
opts, err := f.api.Rapid(path, contentMd5, sliceMd5, size)
653+
if err != nil {
654+
return false, err
655+
}
656+
resp, err := f.srv.CallJSON(ctx, opts, nil, info)
657+
return shouldRetry(ctx, resp, err)
658+
})
659+
if err != nil {
660+
return nil, false, err
661+
}
662+
if info != nil {
663+
return &info.BaseItem, true, nil
664+
} else {
665+
return nil, false, fs.ErrorFileRapidUpload
666+
}
667+
}

0 commit comments

Comments
 (0)