Skip to content

Commit

Permalink
支持设置多个网卡, 更新获取网盘文件秒传信息
Browse files Browse the repository at this point in the history
更新了export 导出文件 和 fixmd5, 因接口的调整, 这两个功能的处理效率有所降低

export功能调整: 导出的文件信息改为保存为文本文件, 可指定导出文件信息的保存路径; 默认不递归导出子目录

fix #537,
fix #402, fix #430, export 已支持出错重试
  • Loading branch information
iikira committed Nov 18, 2018
1 parent cbd5618 commit 77fda04
Show file tree
Hide file tree
Showing 58 changed files with 870 additions and 430 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,6 @@ BaiduPCS-Go ru -length=<文件的大小> -md5=<文件的md5值> -slicemd5=<文
```
# 如果秒传成功, 则保存到网盘路径 /test
BaiduPCS-Go rapidupload -length=56276137 -md5=fbe082d80e90f90f0fb1f94adbbcfa7f -slicemd5=38c6a75b0ec4499271d4ea38a667ab61 -crc32=314332359 /test
# 精简一下, 如果秒传成功, 则保存到网盘路径 /test
BaiduPCS-Go rapidupload -length=56276137 -md5=fbe082d80e90f90f0fb1f94adbbcfa7f /test
```


Expand Down
6 changes: 5 additions & 1 deletion baidupcs/baidupcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const (
// OperationRecycleClear 清空回收站
OperationRecycleClear = "清空回收站"

// OperationGetRapidUploadInfo 获取文件秒传信息
OperationGetRapidUploadInfo = "获取文件秒传信息"
// OperationFixMD5 修复文件md5
OperationFixMD5 = "修复文件md5"
// OperrationMatchPathByShellPattern 通配符匹配文件路径
Expand All @@ -91,6 +93,8 @@ const (
PCSBaiduCom = "pcs.baidu.com"
// PanBaiduCom 网盘首页api地址
PanBaiduCom = "pan.baidu.com"
// YunBaiduCom 网盘首页api地址2
YunBaiduCom = "yun.baidu.com"
// PanAppID 百度网盘appid
PanAppID = "250528"
// NetdiskUA 网盘客户端ua
Expand Down Expand Up @@ -303,7 +307,7 @@ func (pcs *BaiduPCS) UK() (uk int64, pcsError pcserror.Error) {
PanErrorInfo: errInfo,
}

pcsError = handleJSONParse(OperationGetUK, dataReadCloser, &jsonData)
pcsError = pcserror.HandleJSONParse(OperationGetUK, dataReadCloser, &jsonData)
if pcsError != nil {
return
}
Expand Down
3 changes: 2 additions & 1 deletion baidupcs/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ type (
func (pcs *BaiduPCS) updateFilesDirectoriesCache(dirs []string) {
cache := pcs.cacheMap.LazyInitCachePoolOp(OperationFilesDirectoriesList)
for _, v := range dirs {
filesDirectoriesListValidateItf, ok := cache.Load(v + "_" + DefaultOrderOptionsStr)
filesDirectoriesListValidateItf, ok := cache.Load(v + "_" + defaultOrderOptionsStr)
if ok {
filesDirectoriesListValidateItf.(*filesDirectoriesListValidate).SetExpires(false)
}
}
}

// CacheFilesDirectoriesList 缓存获取
func (pcs *BaiduPCS) CacheFilesDirectoriesList(path string, options *OrderOptions) (data FileDirectoryList, pcsError pcserror.Error) {
var (
cache = pcs.cacheMap.LazyInitCachePoolOp(OperationFilesDirectoriesList)
Expand Down
8 changes: 4 additions & 4 deletions baidupcs/cloud_dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (pcs *BaiduPCS) CloudDlAddTask(sourceURL, savePath string) (taskID int64, p
PCSErrInfo: errInfo,
}

pcsError = handleJSONParse(OperationCloudDlAddTask, dataReadCloser, &taskInfo)
pcsError = pcserror.HandleJSONParse(OperationCloudDlAddTask, dataReadCloser, &taskInfo)
if pcsError != nil {
return
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (pcs *BaiduPCS) cloudDlQueryTask(op string, taskIDs []int64) (cl CloudDlTas
PCSErrInfo: errInfo,
}

pcsError = handleJSONParse(OperationCloudDlQueryTask, dataReadCloser, &taskInfo)
pcsError = pcserror.HandleJSONParse(OperationCloudDlQueryTask, dataReadCloser, &taskInfo)
if pcsError != nil {
return
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (pcs *BaiduPCS) CloudDlListTask() (cl CloudDlTaskList, pcsError pcserror.Er
PCSErrInfo: errInfo,
}

pcsError = handleJSONParse(OperationCloudDlListTask, dataReadCloser, &taskInfo)
pcsError = pcserror.HandleJSONParse(OperationCloudDlListTask, dataReadCloser, &taskInfo)
if pcsError != nil {
return
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func (pcs *BaiduPCS) CloudDlClearTask() (total int, pcsError pcserror.Error) {
PCSErrInfo: errInfo,
}

pcsError = handleJSONParse(OperationCloudDlClearTask, dataReadCloser, &clearInfo)
pcsError = pcserror.HandleJSONParse(OperationCloudDlClearTask, dataReadCloser, &clearInfo)
if pcsError != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion baidupcs/dlinkclient/dlinkclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (dc *DlinkClient) genShareURL(method string, param map[string]string) *url.
dlinkURL := url.URL{
Scheme: "https",
Host: DlinkHost,
Path: "/api/v1/pan/share/" + method,
Path: "/api/v1.1/pan/share/" + method,
}

if param != nil {
Expand Down
32 changes: 0 additions & 32 deletions baidupcs/dlinkclient/json.go

This file was deleted.

2 changes: 1 addition & 1 deletion baidupcs/dlinkclient/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (dc *DlinkClient) linkRedirect(op, link string) (nlink string, dlinkError p
return "", redirectRes.DlinkErrInfo
}

dlinkError = handleJSONParse(op, resp.Body, &redirectRes)
dlinkError = pcserror.HandleJSONParse(op, resp.Body, &redirectRes)
if dlinkError != nil {
return
}
Expand Down
10 changes: 5 additions & 5 deletions baidupcs/dlinkclient/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ type (
)

// ShareReg reg
func (dc *DlinkClient) ShareReg(shareURL, passwd string) (short string, dlinkError pcserror.Error) {
func (dc *DlinkClient) ShareReg(shareLink, pwd string) (short string, dlinkError pcserror.Error) {
dc.lazyInit()

var (
u = dc.genShareURL("reg", map[string]string{
"share_url": shareURL,
"passwd": passwd,
"share_link": shareLink,
"pwd": pwd,
})
regStat = RegStat{
DlinkErrInfo: pcserror.NewDlinkErrInfo(OperationReg),
Expand All @@ -59,7 +59,7 @@ func (dc *DlinkClient) ShareReg(shareURL, passwd string) (short string, dlinkErr
return "", regStat.DlinkErrInfo
}

dlinkError = handleJSONParse(OperationReg, resp.Body, &regStat)
dlinkError = pcserror.HandleJSONParse(OperationReg, resp.Body, &regStat)
if dlinkError != nil {
return
}
Expand Down Expand Up @@ -90,7 +90,7 @@ func (dc *DlinkClient) ShareList(short, dir string, page int) (fds []*FileDirect
return nil, fdList.DlinkErrInfo
}

dlinkError = handleJSONParse(OperationList, resp.Body, &fdList)
dlinkError = pcserror.HandleJSONParse(OperationList, resp.Body, &fdList)
if dlinkError != nil {
return
}
Expand Down
24 changes: 22 additions & 2 deletions baidupcs/download.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package baidupcs

import (
"errors"
"github.com/iikira/BaiduPCS-Go/baidupcs/pcserror"
"net/http"
"net/url"
)

var (
// ErrLocateDownloadURLNotFound 未找到下载链接
ErrLocateDownloadURLNotFound = errors.New("locatedownload url not found")
)

type (
// DownloadFunc 下载文件处理函数
DownloadFunc func(downloadURL string, jar http.CookieJar) error
Expand Down Expand Up @@ -71,6 +77,20 @@ func (ui *URLInfo) SingleURL(https bool) *url.URL {
return u
}

// LastURL 返回最后一条下载链接
func (ui *URLInfo) LastURL(https bool) *url.URL {
if len(ui.URLs) < 1 {
return nil
}

u, err := url.Parse(ui.URLs[len(ui.URLs)-1].URL)
if err != nil {
return nil
}
u.Scheme = GetHTTPScheme(https)
return u
}

// DownloadFile 下载单个文件
func (pcs *BaiduPCS) DownloadFile(path string, downloadFunc DownloadFunc) (err error) {
pcs.lazyInit()
Expand Down Expand Up @@ -108,7 +128,7 @@ func (pcs *BaiduPCS) LocateDownloadWithUserAgent(pcspath, ua string) (info *URLI
PCSErrInfo: errInfo,
}

pcsError = handleJSONParse(OperationLocateDownload, dataReadCloser, &jsonData)
pcsError = pcserror.HandleJSONParse(OperationLocateDownload, dataReadCloser, &jsonData)
if pcsError != nil {
return
}
Expand All @@ -134,7 +154,7 @@ func (pcs *BaiduPCS) LocatePanAPIDownload(fidList ...int64) (dlinkInfoList APIDo
jsonData := panAPIDownloadJSON{
PanErrorInfo: pcserror.NewPanErrorInfo(OperationLocatePanAPIDownload),
}
pcsError = handleJSONParse(OperationLocatePanAPIDownload, dataReadCloser, &jsonData)
pcsError = pcserror.HandleJSONParse(OperationLocatePanAPIDownload, dataReadCloser, &jsonData)
if pcsError != nil {
if pcsError.GetErrType() == pcserror.ErrTypeRemoteError {
switch pcsError.GetRemoteErrCode() {
Expand Down
Loading

0 comments on commit 77fda04

Please sign in to comment.