Skip to content

Commit

Permalink
v3.7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
qjfoidnh committed Feb 22, 2021
1 parent f0817da commit ae82230
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ iikira/BaiduPCS-Go was largely inspired by [GangZhuo/BaiduPCS](https://github.co

# 版本更新

**2021.2.23** v3.7.6:

- fix 下载文件报```x509: certificate is valid```错误
- 完善了下载错误的捕获种类
- download增加--fullpath参数,本地目录保留网盘从根目录开始的完整结构

**2021.2.8** v3.7.5:

- fix 某些时候误报stoken缺失
Expand Down
9 changes: 7 additions & 2 deletions internal/pcscommand/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type (
Load int
MaxRetry int
NoCheck bool
FullPath bool
}

// LocateDownloadOption 获取下载链接可选参数
Expand Down Expand Up @@ -157,11 +158,15 @@ func RunDownload(paths []string, options *DownloadOptions) {
// 设置下载并发数
executor.SetParallel(loadCount)
// 设置储存的路径
vPath := v.Path
if !options.FullPath {
vPath = filepath.Join(v.PreBase, filepath.Base(v.Path))
}
if options.SaveTo != "" {
unit.SavePath = filepath.Join(options.SaveTo, filepath.Join(v.PreBase, filepath.Base(v.Path)))
unit.SavePath = filepath.Join(options.SaveTo, vPath)
} else {
// 使用默认的保存路径
unit.SavePath = GetActiveUser().GetSavePath(filepath.Join(v.PreBase, filepath.Base(v.Path)))
unit.SavePath = GetActiveUser().GetSavePath(vPath)
}
info := executor.Append(&unit, options.MaxRetry)
fmt.Printf("[%s] 加入下载队列: %s\n", info.Id(), v.Path)
Expand Down
11 changes: 9 additions & 2 deletions internal/pcsfunctions/pcsdownload/download_task_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ func (dtu *DownloadTaskUnit) handleError(result *taskframework.TaskUnitRunResult
fallthrough
case 31066: // file does not exist
result.NeedRetry = false
case 31297: // file does not exist
result.NeedRetry = false
case 31626: // user is not authorized
//可能是User-Agent不对
//重试
Expand Down Expand Up @@ -293,8 +295,13 @@ func (dtu *DownloadTaskUnit) locateDownload(result *taskframework.TaskUnitRunRes
}

// 更新链接的协议
FixHTTPLinkURL(rawDlinks[0])
dlink := rawDlinks[0].String()
// 跳过nb.cache这种还没有证书的
raw_dlink := rawDlinks[0]
if strings.HasPrefix(rawDlinks[0].Host, "nb.cache") && len(rawDlinks) > 1 {
raw_dlink = rawDlinks[1]
}
FixHTTPLinkURL(raw_dlink)
dlink := raw_dlink.String()

dtu.execPanDownload(dlink, result, &ok)
return
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const (

var (
// Version 版本号
Version = "v3.7.5-devel"
Version = "v3.7.6-devel"

historyFilePath = filepath.Join(pcsconfig.GetConfigDir(), "pcs_command_history.txt")
reloadFn = func(c *cli.Context) error {
Expand Down Expand Up @@ -1066,6 +1066,7 @@ func main() {
Load: c.Int("l"),
MaxRetry: c.Int("retry"),
NoCheck: c.Bool("nocheck"),
FullPath: c.Bool("fullpath"),
}

pcscommand.RunDownload(c.Args(), do)
Expand Down Expand Up @@ -1119,6 +1120,10 @@ func main() {
Name: "nocheck",
Usage: "下载文件完成后不校验文件",
},
cli.BoolFlag{
Name: "fullpath",
Usage: "以网盘完整路径保存到本地",
},
},
},
{
Expand Down
4 changes: 4 additions & 0 deletions requester/downloader/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ func (wer *Worker) Execute() {
fallthrough
case 403: // Forbidden
fallthrough
case 404: // file block not exists
wer.status.statusCode = StatusCodeInternalError
wer.err = errors.New(resp.Status)
return
case 406: // Not Acceptable
wer.status.statusCode = StatusCodeNetError
wer.err = errors.New(resp.Status)
Expand Down
18 changes: 9 additions & 9 deletions requester/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (h *HTTPClient) lazyInit() {
Dial: dial,
// DialTLS: h.dialTLSFunc(),
TLSClientConfig: &tls.Config{
InsecureSkipVerify: !h.https,
InsecureSkipVerify: true,
},
TLSHandshakeTimeout: 10 * time.Second,
DisableKeepAlives: false,
Expand Down Expand Up @@ -77,17 +77,17 @@ func (h *HTTPClient) ResetCookiejar() {
h.Jar, _ = cookiejar.New(nil)
}

// SetHTTPSecure 是否启用 https 安全检查, 默认不检查
// SetHTTPSecure 是否启用 https 安全检查, 强制不检查
func (h *HTTPClient) SetHTTPSecure(b bool) {
h.https = b
h.lazyInit()
if b {
h.transport.TLSClientConfig = nil
} else {
h.transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: !b,
}
}
// if b {
// h.transport.TLSClientConfig = nil
// } else {
h.transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
// }
}

// SetKeepAlive 设置 Keep-Alive
Expand Down

0 comments on commit ae82230

Please sign in to comment.