Skip to content

Commit 5ca13ec

Browse files
authored
Merge pull request #409 from qiniu/fix/configurable-uc-and-update-query-region
configurable uc and update query region
2 parents ee79498 + 2fa981e commit 5ca13ec

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## CHANGE LOG
22
## NEXT VERSION
33
- 对象存储,修复无法对 key 为空字符串的对象进行操作
4+
- 对象存储,查询区域域名支持配置 UC 地址
5+
- 对象存储,查询区域域名接口升级
46

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

qiniu/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ exports.prepareZone = function (ctx, accessKey, bucket, callback) {
332332
}
333333
// update object
334334
ctx.config.zone = cZoneInfo;
335-
ctx.config.zoneExpire = cZoneExpire + parseInt(Date.now() / 1000);
335+
ctx.config.zoneExpire = cZoneExpire + Math.trunc(Date.now() / 1000);
336336
callback(null, ctx);
337337
});
338338
}

qiniu/zone.js

+23-24
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ exports.Zone_ap_northeast_1 = new conf.Zone([
7474

7575
exports.getZoneInfo = function (accessKey, bucket, callbackFunc) {
7676
const apiAddr = util.format(
77-
'https://uc.qbox.me/v2/query?ak=%s&bucket=%s',
77+
'https://%s/v4/query?ak=%s&bucket=%s',
78+
conf.UC_HOST,
7879
accessKey,
7980
bucket
8081
);
@@ -91,37 +92,35 @@ exports.getZoneInfo = function (accessKey, bucket, callbackFunc) {
9192
return;
9293
}
9394

94-
const zoneData = JSON.parse(respData);
95-
const srcUpHosts = [];
96-
const cdnUpHosts = [];
95+
let zoneData;
96+
try {
97+
const hosts = JSON.parse(respData).hosts;
98+
if (!hosts || !hosts.length) {
99+
respErr = new Error('no host available: ' + respData);
100+
callbackFunc(respErr, null, null);
101+
return;
102+
}
103+
zoneData = hosts[0];
104+
} catch (err) {
105+
callbackFunc(err, null, null);
106+
return;
107+
}
108+
let srcUpHosts = [];
109+
let cdnUpHosts = [];
97110
let zoneExpire = 0;
98111

99112
try {
100113
zoneExpire = zoneData.ttl;
101114
// read src hosts
102-
zoneData.up.src.main.forEach(function (host) {
103-
srcUpHosts.push(host);
104-
});
105-
if (zoneData.up.src.backup) {
106-
zoneData.up.src.backup.forEach(function (host) {
107-
srcUpHosts.push(host);
108-
});
109-
}
115+
srcUpHosts = zoneData.up.domains;
110116

111117
// read acc hosts
112-
zoneData.up.acc.main.forEach(function (host) {
113-
cdnUpHosts.push(host);
114-
});
115-
if (zoneData.up.acc.backup) {
116-
zoneData.up.acc.backup.forEach(function (host) {
117-
cdnUpHosts.push(host);
118-
});
119-
}
118+
cdnUpHosts = zoneData.up.domains;
120119

121-
const ioHost = zoneData.io.src.main[0];
122-
const rsHost = zoneData.rs.acc.main[0];
123-
const rsfHost = zoneData.rsf.acc.main[0];
124-
const apiHost = zoneData.api.acc.main[0];
120+
const ioHost = zoneData.io.domains[0];
121+
const rsHost = zoneData.rs.domains[0];
122+
const rsfHost = zoneData.rsf.domains[0];
123+
const apiHost = zoneData.api.domains[0];
125124
const zoneInfo = new conf.Zone(
126125
srcUpHosts,
127126
cdnUpHosts,

0 commit comments

Comments
 (0)