Skip to content

Commit

Permalink
bugfix: d -locate
Browse files Browse the repository at this point in the history
  • Loading branch information
iikira committed Nov 12, 2018
1 parent 0007020 commit cbd5618
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions internal/pcscommand/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,21 +474,12 @@ func RunDownload(paths []string, options *DownloadOptions) {
// 获取直链下载
var rawDlinks []*url.URL
rawDlinks, err = getLocateDownloadLinks(task.path)
if err != nil {
if err == nil {
handleHTTPLinkURL(rawDlinks[0])
dlink = rawDlinks[0].String()
dlinks = make([]string, 0, len(rawDlinks)-1)
for _, rawDlink := range rawDlinks[1:len(rawDlinks)] {
if rawDlink == nil {
continue
}

if pcsconfig.Config.EnableHTTPS() {
// 使用https
if rawDlink.Scheme == "http" {
rawDlink.Scheme = "https"
}
}

handleHTTPLinkURL(rawDlink)
dlinks = append(dlinks, rawDlink.String())
}
}
Expand All @@ -509,7 +500,6 @@ func RunDownload(paths []string, options *DownloadOptions) {
}

if (options.IsShareDownload || options.IsLocateDownload || options.IsLocatePanAPIDownload) && err == nil {
dlink = handleHTTPLink(dlink)
pcsCommandVerbose.Infof("[%d] 获取到下载链接: %s\n", task.ID, dlink)
client := pcsconfig.Config.HTTPClient()
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
Expand Down Expand Up @@ -733,19 +723,12 @@ func getLocatePanLink(pcs *baidupcs.BaiduPCS, fsID int64) (dlink string, err err
return
}

func handleHTTPLink(link string) (nlink string) {
func handleHTTPLinkURL(linkURL *url.URL) {
if pcsconfig.Config.EnableHTTPS() {
u, err := url.Parse(link)
if err != nil {
return link
}

if u.Scheme == "http" {
u.Scheme = "https"
if linkURL.Scheme == "http" {
linkURL.Scheme = "https"
}
return u.String()
}
return link
}

// fileExist 检查文件是否存在,
Expand Down

0 comments on commit cbd5618

Please sign in to comment.