Skip to content

Commit

Permalink
v3.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
qjfoidnh committed Jan 21, 2021
1 parent d03a220 commit c1de2ff
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 70 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ iikira/BaiduPCS-Go was largely inspired by [GangZhuo/BaiduPCS](https://github.co

# 版本更新

**2021.1.22** v3.7.3:

- 分享支持自定义分享码和有效天数
- 转存支持转存完毕后自动下载到默认目录
- 增加恢复默认配置功能
- tree命令支持指定输出最大层数和带fsid输出

**2021.1.9** v3.7.2:

- 基本修复了登录验证失效问题([#15](https://github.com/qjfoidnh/BaiduPCS-Go/issues/15))
Expand Down
10 changes: 5 additions & 5 deletions baidupcs/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type (
Public int `json:"public"` // 是否为公开分享
TypicalCategory int `json:"typicalCategory"` // 文件类型
TypicalPath string `json:"typicalPath"`
Valid string // 是否过期
}

shareSURLInfo struct {
Expand Down Expand Up @@ -64,12 +65,11 @@ var (

// ShareSet 分享文件
func (pcs *BaiduPCS) ShareSet(paths []string, option *ShareOption) (s *Shared, pcsError pcserror.Error) {
if option == nil {
option = &ShareOption{CreatePasswd(), 0}
if option.Password == "" || len(option.Password) != 4 {
option = &ShareOption{CreatePasswd(), option.Period}
}
passwd := option.Password

dataReadCloser, pcsError := pcs.PrepareSharePSet(paths, passwd, option.Period)
dataReadCloser, pcsError := pcs.PrepareSharePSet(paths, option.Password, option.Period)
if pcsError != nil {
return
}
Expand All @@ -92,7 +92,7 @@ func (pcs *BaiduPCS) ShareSet(paths []string, option *ShareOption) (s *Shared, p
errInfo.Err = ErrShareLinkNotFound
return nil, errInfo
}
jsonData.Pwd = passwd
jsonData.Pwd = option.Password

return jsonData.Shared, nil
}
Expand Down
63 changes: 62 additions & 1 deletion baidupcs/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ import (
"io/ioutil"
"net/http"
"net/url"
"path"
"path/filepath"
"regexp"
"strings"

"github.com/tidwall/gjson"
)

type (
// ShareOption 分享可选项
TransferOption struct {
Download bool // 是否直接开始下载
}
)

func (pcs *BaiduPCS) GenerateShareQueryURL(subPath string, params map[string]string) *url.URL {
shareURL := &url.URL{
Scheme: GetHTTPScheme(true),
Expand Down Expand Up @@ -140,6 +148,7 @@ func (pcs *BaiduPCS) AccessSharePage(featurestr string, first bool) (tokens map[

func (pcs *BaiduPCS) GenerateRequestQuery(mode string, params map[string]string) (res map[string]string) {
res = make(map[string]string)
res["ErrNo"] = "0"
headers := map[string]string{
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
"Referer": params["referer"],
Expand All @@ -152,22 +161,25 @@ func (pcs *BaiduPCS) GenerateRequestQuery(mode string, params map[string]string)
postdata["path"] = params["path"]
dataReadCloser, panError := pcs.sendReqReturnReadCloser(reqTypePan, OperationShareFileSavetoLocal, mode, params["shareUrl"], postdata, headers)
if panError != nil {
res["ErrNo"] = "1"
res["ErrMsg"] = "网络错误"
return
}
defer dataReadCloser.Close()
body, err := ioutil.ReadAll(dataReadCloser)
res["ErrMsg"] = "0"
if err != nil {
res["ErrNo"] = "-1"
res["ErrMsg"] = "未知错误"
return
}
if !gjson.Valid(string(body)) {
res["ErrNo"] = "2"
res["ErrMsg"] = "返回json解析错误"
return
}
errno := gjson.Get(string(body), `errno`).Int()
if errno != 0 {
res["ErrNo"] = "3"
res["ErrMsg"] = "获取分享项元数据错误"
if mode == "POST" && errno == 12 {
path := gjson.Get(string(body), `info.0.path`).String()
Expand All @@ -176,8 +188,11 @@ func (pcs *BaiduPCS) GenerateRequestQuery(mode string, params map[string]string)
target_file_nums := gjson.Get(string(body), `target_file_nums`).Int()
target_file_nums_limit := gjson.Get(string(body), `target_file_nums_limit`).Int()
if target_file_nums > target_file_nums_limit {
res["ErrNo"] = "4"
res["ErrMsg"] = fmt.Sprintf("转存文件数%d超过当前用户上限, 当前用户单次最大转存数%d", target_file_nums, target_file_nums_limit)
res["limit"] = fmt.Sprintf("%d", target_file_nums_limit)
} else if _errno == -30 {
res["ErrNo"] = "9"
res["ErrMsg"] = fmt.Sprintf("当前目录下已有%s同名文件/文件夹", file)
} else {
res["ErrMsg"] = fmt.Sprintf("未知错误, 错误代码%d", _errno)
Expand All @@ -188,8 +203,54 @@ func (pcs *BaiduPCS) GenerateRequestQuery(mode string, params map[string]string)
return
}
_, res["filename"] = filepath.Split(gjson.Get(string(body), `info.0.path`).String())
filenames := gjson.Get(string(body), `info.#.path`).Array()
filenames_str := ""
for _, _path := range filenames {
filenames_str += path.Base(_path.String())+","
}
res["filenames"] = filenames_str
if len(gjson.Get(string(body), `info.#.fsid`).Array()) > 1 {
res["filename"] += "等多个文件"
}
return
}

func (pcs *BaiduPCS) SuperTransfer(params map[string]string, limit string) {
//headers := map[string]string{
// "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
// "Referer": params["referer"],
//}
//limit_num, _ := strconv.Atoi(limit)
//fsidlist_str := params["fs_id"]
//fsidlist := strings.Split(fsidlist_str[1:len(fsidlist_str)-1], ",")
//listUrl := &url.URL{
// Scheme: GetHTTPScheme(true),
// Host: PanBaiduCom,
// Path: "/share/list",
//}
//uv := listUrl.Query()
//uv.Set("app_id", PanAppID)
//uv.Set("channel", "chunlei")
//uv.Set("clienttype", "0")
//uv.Set("web", "1")
//uv.Set("page", "1")
//uv.Set("num", "100")
//uv.Set("shorturl", params["shorturl"])
//uv.Set("root", "1")
//dataReadCloser, panError := pcs.sendReqReturnReadCloser(reqTypePan, OperationShareFileSavetoLocal, http.MethodGet, listUrl.String(), nil, headers)
//if panError != nil {
// res["ErrNo"] = "1"
// res["ErrMsg"] = "网络错误"
// return
//}
//defer dataReadCloser.Close()
//body, err := ioutil.ReadAll(dataReadCloser)
//res["ErrNo"] = "-1"
//if err != nil {
// res["ErrMsg"] = "未知错误"
// return
//}
return


}
Loading

0 comments on commit c1de2ff

Please sign in to comment.