Skip to content

Commit 94057fa

Browse files
committedFeb 16, 2022
feat:getObjectUrl支持全球加速参数
1 parent 69c073e commit 94057fa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

‎src/base.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -2991,12 +2991,13 @@ function getAuth(params) {
29912991
*/
29922992
function getObjectUrl(params, callback) {
29932993
var self = this;
2994+
var useAccelerate = params.UseAccelerate === undefined ? self.options.UseAccelerate : params.UseAccelerate;
29942995
var url = getUrl({
29952996
ForcePathStyle: self.options.ForcePathStyle,
29962997
protocol: params.Protocol || self.options.Protocol,
29972998
domain: params.Domain || self.options.Domain,
29982999
bucket: params.Bucket,
2999-
region: params.Region,
3000+
region: useAccelerate ? 'accelerate' : params.Region,
30003001
object: params.Key,
30013002
});
30023003

@@ -3016,7 +3017,7 @@ function getObjectUrl(params, callback) {
30163017
}
30173018

30183019
// 签名加上 Host,避免跨桶访问
3019-
var SignHost = getSignHost.call(this, {Bucket: params.Bucket, Region: params.Region, Url: url});
3020+
var SignHost = getSignHost.call(this, {Bucket: params.Bucket, Region: params.Region, UseAccelerate: params.UseAccelerate, Url: url});
30203021
var AuthData = getAuthorizationAsync.call(this, {
30213022
Action: ((params.Method || '').toUpperCase() === 'PUT' ? 'name/cos:PutObject' : 'name/cos:GetObject'),
30223023
Bucket: params.Bucket || '',
@@ -3185,12 +3186,13 @@ function getUrl(params) {
31853186

31863187
var getSignHost = function (opt) {
31873188
if (!opt.Bucket || !opt.Region) return '';
3189+
var useAccelerate = opt.UseAccelerate === undefined ? this.options.UseAccelerate : opt.UseAccelerate;
31883190
var url = opt.Url || getUrl({
31893191
ForcePathStyle: this.options.ForcePathStyle,
31903192
protocol: this.options.Protocol,
31913193
domain: this.options.Domain,
31923194
bucket: opt.Bucket,
3193-
region: this.options.UseAccelerate ? 'accelerate' : opt.Region,
3195+
region: useAccelerate ? 'accelerate' : opt.Region,
31943196
});
31953197
var urlHost = url.replace(/^https?:\/\/([^/]+)(\/.*)?$/, '$1');
31963198
var standardHostReg = new RegExp('^([a-z\\d-]+-\\d+\\.)?(cos|cosv6|ci|pic)\\.([a-z\\d-]+)\\.myqcloud\\.com$');

0 commit comments

Comments
 (0)
Please sign in to comment.