Skip to content

Commit 3cdad62

Browse files
authored
Merge pull request #185 from codedogfish/master
fix fetch uphosts bug
2 parents dfc5da2 + a78f369 commit 3cdad62

File tree

5 files changed

+52
-16
lines changed

5 files changed

+52
-16
lines changed

dist/qiniu.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*!
2-
* qiniu-js-sdk v1.0.17-beta
2+
* qiniu-js-sdk v1.0.17.1
33
*
44
* Copyright 2015 by Qiniu
55
* Released under GPL V2 License.
66
*
77
* GitHub: http://github.com/qiniu/js-sdk
88
*
9-
* Date: 2016-9-30
9+
* Date: 2016-10-11
1010
*/
1111

1212
/*global plupload ,mOxie*/
@@ -595,14 +595,25 @@ function QiniuJsSDK() {
595595
return result;
596596
};
597597

598-
var getUpHosts = function(uptoken) {
598+
var getPutPolicy = function (uptoken) {
599599
var segments = uptoken.split(":");
600600
var ak = segments[0];
601601
var putPolicy = that.parseJSON(that.URLSafeBase64Decode(segments[2]));
602+
putPolicy.ak = ak;
603+
if (putPolicy.scope.indexOf(":") >= 0) {
604+
putPolicy.bucket = putPolicy.scope.split(":")[0];
605+
putPolicy.key = putPolicy.scope.split(":")[1];
606+
} else {
607+
putPolicy.bucket = putPolicy.scope;
608+
}
609+
return putPolicy;
610+
};
611+
612+
var getUpHosts = function(uptoken) {
613+
var putPolicy = getPutPolicy(uptoken);
602614
// var uphosts_url = "//uc.qbox.me/v1/query?ak="+ak+"&bucket="+putPolicy.scope;
603615
// IE 9- is not support protocal relative url
604-
var uphosts_url = window.location.protocol + "//uc.qbox.me/v1/query?ak="+ak+"&bucket="+putPolicy.scope;
605-
logger.debug("ak: ", ak);
616+
var uphosts_url = window.location.protocol + "//uc.qbox.me/v1/query?ak=" + putPolicy.ak + "&bucket=" + putPolicy.bucket;
606617
logger.debug("putPolicy: ", putPolicy);
607618
logger.debug("get uphosts from: ", uphosts_url);
608619
var ie = that.detectIEVersion();
@@ -718,7 +729,15 @@ function QiniuJsSDK() {
718729

719730
// get file key according with the user passed options
720731
var getFileKey = function(up, file, func) {
721-
// TODO: save_key can read from scope of token
732+
// WARNING
733+
// When you set the key in putPolicy by "scope": "bucket:key"
734+
// You should understand the risk of override a file in the bucket
735+
// So the code below that automatically get key from uptoken has been commented
736+
// var putPolicy = getPutPolicy(that.token)
737+
// if (putPolicy.key) {
738+
// logger.debug("key is defined in putPolicy.scope: ", putPolicy.key)
739+
// return putPolicy.key
740+
// }
722741
var key = '',
723742
unique_names = false;
724743
if (!op.save_key) {
@@ -923,7 +942,6 @@ function QiniuJsSDK() {
923942
}
924943
}
925944

926-
927945
up.setOption({
928946
'url': qiniuUploadUrl,
929947
'multipart': true,

0 commit comments

Comments
 (0)