Skip to content

Commit 36b7e84

Browse files
authored
Merge pull request #408 from qiniu/fix/update-image-domain
update source image domain and add tests
2 parents 5ca13ec + 9cb0023 commit 36b7e84

File tree

3 files changed

+47
-16
lines changed

3 files changed

+47
-16
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- 对象存储,修复无法对 key 为空字符串的对象进行操作
44
- 对象存储,查询区域域名支持配置 UC 地址
55
- 对象存储,查询区域域名接口升级
6+
- 对象存储,更新设置镜像源的域名
67

78
## 7.8.0
89
- 移除不推荐域名,并增加 亚太-首尔 和 华东-浙江2 固定区域

qiniu/storage/rs.js

+20-16
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,21 @@ function changeTypeReq(mac, config, bucket, key, newType, callbackFunc) {
373373
);
374374
}
375375

376-
// 设置空间镜像源
377-
// @link https://developer.qiniu.com/kodo/api/1370/mirror
378-
// @param bucket 空间名称
379-
// @param srcSiteUrl 镜像源地址
380-
// @param srcHost 镜像Host
381-
// @param callbackFunc(err, respBody, respInfo) 回调函数
382-
const PU_HOST = 'http://pu.qbox.me:10200';
376+
/**
377+
* 设置空间镜像源
378+
* @link https://developer.qiniu.com/kodo/3966/bucket-image-source
379+
* @param {string} bucket 空间名称
380+
* @param {string} srcSiteUrl 镜像源地址
381+
* @param {string} srcHost 镜像Host
382+
* @param {function(err: error, respBody: object, respInfo: object)} callbackFunc 回调函数
383+
*/
383384
BucketManager.prototype.image = function (bucket, srcSiteUrl, srcHost,
384385
callbackFunc) {
385-
var encodedSrcSite = util.urlsafeBase64Encode(srcSiteUrl);
386-
var requestURI = PU_HOST + '/image/' + bucket + '/from/' + encodedSrcSite;
386+
const encodedSrcSite = util.urlsafeBase64Encode(srcSiteUrl);
387+
const scheme = this.config.useHttpsDomain ? 'https://' : 'http://';
388+
let requestURI = scheme + conf.UC_HOST + '/image/' + bucket + '/from/' + encodedSrcSite;
387389
if (srcHost) {
388-
var encodedHost = util.urlsafeBase64Encode(srcHost);
390+
const encodedHost = util.urlsafeBase64Encode(srcHost);
389391
requestURI += '/host/' + encodedHost;
390392
}
391393
rpc.postWithOptions(
@@ -398,13 +400,15 @@ BucketManager.prototype.image = function (bucket, srcSiteUrl, srcHost,
398400
);
399401
};
400402

401-
// 取消设置空间镜像源
402-
// @link https://developer.qiniu.com/kodo/api/1370/mirror
403-
// @param bucket 空间名称
404-
// @param callbackFunc(err, respBody, respInfo) 回调函数
403+
/**
404+
* 取消设置空间镜像源
405+
* @param {string} bucket 空间名称
406+
* @param {function(err: error, respBody: object, respInfo: object)} callbackFunc 回调函数
407+
*/
405408
BucketManager.prototype.unimage = function (bucket, callbackFunc) {
406-
var requestURI = PU_HOST + '/unimage/' + bucket;
407-
var digest = util.generateAccessTokenV2(this.mac, requestURI, 'POST', 'application/x-www-form-urlencoded');
409+
const scheme = this.config.useHttpsDomain ? 'https://' : 'http://';
410+
const requestURI = scheme + conf.UC_HOST + '/unimage/' + bucket;
411+
const digest = util.generateAccessTokenV2(this.mac, requestURI, 'POST', 'application/x-www-form-urlencoded');
408412
rpc.postWithoutForm(requestURI, digest, callbackFunc);
409413
};
410414

test/rs.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -901,4 +901,30 @@ describe('test start bucket manager', function () {
901901
});
902902
});
903903
});
904+
905+
describe('test bucket image source', function () {
906+
it('test set image', function (done) {
907+
bucketManager.image(
908+
srcBucket,
909+
'http://devtools.qiniu.com/',
910+
'devtools.qiniu.com',
911+
function (err, respBody, respInfo) {
912+
should.not.exist(err, JSON.stringify(respInfo));
913+
respInfo.statusCode.should.be.eql(200, JSON.stringify(respInfo));
914+
done();
915+
}
916+
);
917+
});
918+
919+
it('test unset image', function (done) {
920+
bucketManager.unimage(
921+
srcBucket,
922+
function (err, respBody, respInfo) {
923+
should.not.exist(err, JSON.stringify(respInfo));
924+
respInfo.statusCode.should.be.eql(200, JSON.stringify(respInfo));
925+
done();
926+
}
927+
);
928+
});
929+
});
904930
});

0 commit comments

Comments
 (0)