Skip to content

Commit

Permalink
修复转存失败问题
Browse files Browse the repository at this point in the history
  • Loading branch information
qjfoidnh committed Oct 10, 2023
1 parent e239a1e commit a4d0a34
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ iikira/BaiduPCS-Go was largely inspired by [GangZhuo/BaiduPCS](https://github.co
[离线下载](#离线下载), 支持http/https/ftp/电驴/磁力链协议.

# 版本更新
**2023.09.29** v3.9.5
**2023.09.30** v3.9.5
- 恢复秒传转存功能, 使用前需设置accessToken, 参见setastoken --help
- 本地文件上传用秒传无须accessToken
- fix #301
Expand Down
1 change: 0 additions & 1 deletion baidupcs/baidupcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ func (pcs *BaiduPCS) generatePCSURL2(subPath, method string, param ...map[string
}

uv := pcsURL2.Query()
uv.Set("app_id", PanAppID)
uv.Set("method", method)
for k := range param {
for k2 := range param[k] {
Expand Down
33 changes: 13 additions & 20 deletions baidupcs/cloud_dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type (
// cloudDlTaskInfo 用于解析远程返回的JSON
cloudDlTaskInfo struct {
Status string `json:"status"`
TaskID string `json:"task_id"`
FileSize string `json:"file_size"`
FinishedSize string `json:"finished_size"`
CreateTime string `json:"create_time"`
Expand All @@ -59,10 +60,6 @@ type (
Result int `json:"result"`
}

taskIDJSON struct {
TaskID string `json:"task_id"`
}

taskIDInt64JSON struct {
TaskID int64 `json:"task_id"`
}
Expand All @@ -78,7 +75,7 @@ type (
}

cloudDlListTaskJSON struct {
TaskInfo []*taskIDJSON `json:"task_info"`
TaskInfo []*cloudDlTaskInfo `json:"task_info"`
*pcserror.PCSErrInfo
}

Expand Down Expand Up @@ -225,24 +222,20 @@ func (pcs *BaiduPCS) CloudDlListTask() (cl CloudDlTaskList, pcsError pcserror.Er
if len(taskInfo.TaskInfo) <= 0 {
return CloudDlTaskList{}, nil
}

var (
taskID int64
taskIDs = make([]int64, 0, len(taskInfo.TaskInfo))
)
cl = make([]*CloudDlTaskInfo, 0, len(taskInfo.TaskInfo))
var v2 *CloudDlTaskInfo
for _, v := range taskInfo.TaskInfo {
var err error
if v == nil {
continue
}
var err error
if taskID, err = strconv.ParseInt(v.TaskID, 10, 64); err == nil {
taskIDs = append(taskIDs, taskID)
v2 = v.convert()
v2.TaskID, err = strconv.ParseInt(v.TaskID, 10, 64)
if err != nil {
continue
}
}

cl, pcsError = pcs.cloudDlQueryTask(OperationCloudDlListTask, taskIDs)
if pcsError != nil {
return nil, pcsError
v2.ParseText()
cl = append(cl, v2)
}

return cl, nil
Expand Down Expand Up @@ -328,9 +321,9 @@ func (ci *CloudDlTaskInfo) ParseText() {
func (cl CloudDlTaskList) String() string {
builder := &strings.Builder{}
tb := pcstable.NewTable(builder)
tb.SetHeader([]string{"#", "任务ID", "任务名称", "文件大小", "创建日期", "保存路径", "资源地址", "状态"})
tb.SetHeader([]string{"#", "任务ID", "任务名称", "创建日期", "保存路径", "资源地址", "状态"})
for k, v := range cl {
tb.Append([]string{strconv.Itoa(k), strconv.FormatInt(v.TaskID, 10), v.TaskName, converter.ConvertFileSize(v.FileSize), pcstime.FormatTime(v.CreateTime), path.Clean(v.SavePath), v.SourceURL, v.StatusText})
tb.Append([]string{strconv.Itoa(k), strconv.FormatInt(v.TaskID, 10), v.TaskName, pcstime.FormatTime(v.CreateTime), path.Clean(v.SavePath), v.SourceURL, v.StatusText})
}
tb.Render()
return builder.String()
Expand Down
26 changes: 8 additions & 18 deletions baidupcs/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,19 +403,12 @@ func (pcs *BaiduPCS) PrepareLocateDownload(pcspath string) (dataReadCloser io.Re
"check_blue": []string{"1"},
"es": []string{"1"},
"esl": []string{"1"},
//"dtype": []string{"1"},
//"err_ver": []string{"1.0"},
//"ehps": []string{"1"},
//"eck": []string{"1"},
"app_id": []string{PanAppID},
"method": []string{"locatedownload"},
"path": []string{pcspath},
"ver": []string{"4.0"},
//"vip": []string{"2"},
"clienttype": []string{"17"},
//"version": []string{"2.2.91.26"},
"channel": []string{"0"},
//"version_app": []string{"11.6.3"},
"apn_id": []string{"1_0"},
"freeisp": []string{"0"},
"queryfree": []string{"0"},
Expand Down Expand Up @@ -459,10 +452,6 @@ func (pcs *BaiduPCS) PrepareLocatePanAPIDownload(fidList ...int64) (dataReadClos
// PrepareUpload 上传单个文件, 只返回服务器响应数据和错误信息(分片上传中的预上传部分)
func (pcs *BaiduPCS) PrepareUpload(policy string, targetPath string, uploadFunc UploadFunc) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
pcs.lazyInit()
//pcsError = pcs.checkIsdir(OperationUpload, targetPath, policy)
//if pcsError != nil {
// return nil, pcsError
//}

pcsURL := pcs.generatePCSURL("file", "upload", map[string]string{
"path": targetPath,
Expand Down Expand Up @@ -610,9 +599,11 @@ func (pcs *BaiduPCS) PrepareUploadSuperfile2(uploadid, targetPath string, partse
func (pcs *BaiduPCS) PrepareCloudDlAddTask(sourceURL, savePath string) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
pcs.lazyInit()
pcsURL2 := pcs.generatePCSURL2("services/cloud_dl", "add_task", map[string]string{
"app_id": PanAppID,
"task_from": "0",
"selected_idx": "1",
"save_path": savePath,
"source_url": sourceURL,
"timeout": "2147483647",
})
baiduPCSVerbose.Infof("%s URL: %s\n", OperationCloudDlAddTask, pcsURL2)

Expand All @@ -625,16 +616,13 @@ func (pcs *BaiduPCS) PrepareCloudDlAddTask(sourceURL, savePath string) (dataRead
func (pcs *BaiduPCS) PrepareCloudDlQueryTask(taskIDs string) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
pcs.lazyInit()
pcsURL2 := pcs.generatePCSURL2("services/cloud_dl", "query_task", map[string]string{
"app_id": PanAppID,
"op_type": "1",
"task_ids": taskIDs,
})
baiduPCSVerbose.Infof("%s URL: %s\n", OperationCloudDlQueryTask, pcsURL2)

// 表单上传
mr := multipartreader.NewMultipartReader()
mr.AddFormFeild("task_ids", strings.NewReader(taskIDs))
mr.CloseMultipart()

dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePCS, OperationCloudDlQueryTask, http.MethodPost, pcsURL2.String(), mr, nil)
dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePCS, OperationCloudDlQueryTask, http.MethodGet, pcsURL2.String(), nil, nil)
return
}

Expand All @@ -646,6 +634,7 @@ func (pcs *BaiduPCS) PrepareCloudDlListTask() (dataReadCloser io.ReadCloser, pcs
"status": "255",
"start": "0",
"limit": "1000",
"app_id": PanAppID,
})
baiduPCSVerbose.Infof("%s URL: %s\n", OperationCloudDlListTask, pcsURL2)

Expand All @@ -656,6 +645,7 @@ func (pcs *BaiduPCS) PrepareCloudDlListTask() (dataReadCloser io.ReadCloser, pcs
func (pcs *BaiduPCS) prepareCloudDlCDTask(opreation, method string, taskID int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
pcs.lazyInit()
pcsURL2 := pcs.generatePCSURL2("services/cloud_dl", method, map[string]string{
"app_id": PanAppID,
"task_id": strconv.FormatInt(taskID, 10),
})
baiduPCSVerbose.Infof("%s URL: %s\n", opreation, pcsURL2)
Expand Down

0 comments on commit a4d0a34

Please sign in to comment.