Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

阿里云盘下载优先使用cdn直链 #6645

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
13 changes: 11 additions & 2 deletions drivers/aliyundrive/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,26 @@ func (d *AliDrive) Link(ctx context.Context, file model.Obj, args model.LinkArgs
"file_id": file.GetID(),
"expire_sec": 14400,
}
res, err, _ := d.request("https://api.alipan.com/v2/file/get_download_url", http.MethodPost, func(req *resty.Request) {
res, err, _ := d.request("https://bj29.api.aliyunpds.com/v2/file/get_download_url", http.MethodPost, func(req *resty.Request) {
Copy link
Member

@SeanHeuc SeanHeuc Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replacing the official url with a third-party one is never a good practice. Alipan official could change this url anytime, and then many user will have trouble use this driver.
please put this url as an option if this can provide acceleration benefit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这并不是一个第三方的url,相反,它是阿里云盘的上游服务pds(阿里云的一个云服务产品),阿里云盘在此基础上封装了一层(可能伴随着一些接口信息的阉割),一般来说,它比阿里云盘的接口更可靠。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as long as it's not an official url in the Aliyun-Open doc, it's stability is not guaranteed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就像 @SeanHeuc 说的,请将其作为一个选项 而不是直接修改

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太熟悉go语言,回头看看go的语法,有时间再改改

req.SetBody(data)
}, nil)
if err != nil {
return nil, err
}
// 尝试获取 cdn_url
cdnURL := utils.Json.Get(res, "cdn_url").ToString()
var downloadURL string
if cdnURL != nil && cdnURL != "" {
downloadURL = cdnURL
} else {
// 如果 cdn_url 为空,则获取 url
downloadURL = utils.Json.Get(res, "url").ToString()
}
return &model.Link{
Header: http.Header{
"Referer": []string{"https://www.alipan.com/"},
},
URL: utils.Json.Get(res, "url").ToString(),
URL: downloadURL,
}, nil
}

Expand Down