Skip to content

Commit 84d4f78

Browse files
authored
Merge pull request #146 from livehigh/feat/getObject-support-useAccelerate
Feat/get object support use accelerate
2 parents e513768 + 59e79fd commit 84d4f78

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

dist/cos-js-sdk-v5.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7871,12 +7871,13 @@ function getAuth(params) {
78717871
*/
78727872
function getObjectUrl(params, callback) {
78737873
var self = this;
7874+
var useAccelerate = params.UseAccelerate === undefined ? self.options.UseAccelerate : params.UseAccelerate;
78747875
var url = getUrl({
78757876
ForcePathStyle: self.options.ForcePathStyle,
78767877
protocol: params.Protocol || self.options.Protocol,
78777878
domain: params.Domain || self.options.Domain,
78787879
bucket: params.Bucket,
7879-
region: params.Region,
7880+
region: useAccelerate ? 'accelerate' : params.Region,
78807881
object: params.Key
78817882
});
78827883

@@ -7896,7 +7897,7 @@ function getObjectUrl(params, callback) {
78967897
}
78977898

78987899
// 签名加上 Host,避免跨桶访问
7899-
var SignHost = getSignHost.call(this, { Bucket: params.Bucket, Region: params.Region, Url: url });
7900+
var SignHost = getSignHost.call(this, { Bucket: params.Bucket, Region: params.Region, UseAccelerate: params.UseAccelerate, Url: url });
79007901
var AuthData = getAuthorizationAsync.call(this, {
79017902
Action: (params.Method || '').toUpperCase() === 'PUT' ? 'name/cos:PutObject' : 'name/cos:GetObject',
79027903
Bucket: params.Bucket || '',
@@ -8057,12 +8058,13 @@ function getUrl(params) {
80578058

80588059
var getSignHost = function (opt) {
80598060
if (!opt.Bucket || !opt.Region) return '';
8061+
var useAccelerate = opt.UseAccelerate === undefined ? this.options.UseAccelerate : opt.UseAccelerate;
80608062
var url = opt.Url || getUrl({
80618063
ForcePathStyle: this.options.ForcePathStyle,
80628064
protocol: this.options.Protocol,
80638065
domain: this.options.Domain,
80648066
bucket: opt.Bucket,
8065-
region: this.options.UseAccelerate ? 'accelerate' : opt.Region
8067+
region: useAccelerate ? 'accelerate' : opt.Region
80668068
});
80678069
var urlHost = url.replace(/^https?:\/\/([^/]+)(\/.*)?$/, '$1');
80688070
var standardHostReg = new RegExp('^([a-z\\d-]+-\\d+\\.)?(cos|cosv6|ci|pic)\\.([a-z\\d-]+)\\.myqcloud\\.com$');

dist/cos-js-sdk-v5.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/base.js

Lines changed: 5 additions & 3 deletions
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 || '',
@@ -3186,12 +3187,13 @@ function getUrl(params) {
31863187

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

0 commit comments

Comments
 (0)