Fix: blocking while get uptoken

pull/141/head
HFO4 7 years ago
parent 422f9d8d6a
commit 65dcedb3ca

@ -170,6 +170,6 @@ class File extends Controller{
} }
} }
return FileManage::createFolder($dirName,$dirPosition,$this->userObj->uid); return json(FileManage::createFolder($dirName,$dirPosition,$this->userObj->uid));
} }
} }

@ -543,7 +543,9 @@ class FileManage extends Model{
$fileList = Db::name('files')->where('upload_user',$uid)->where('dir',$path)->select(); $fileList = Db::name('files')->where('upload_user',$uid)->where('dir',$path)->select();
$dirList = Db::name('folders')->where('owner',$uid)->where('position',$path)->select(); $dirList = Db::name('folders')->where('owner',$uid)->where('position',$path)->select();
$count= 0; $count= 0;
$fileListData=[]; $fileListData=[
"result"=>[],
];
foreach ($dirList as $key => $value) { foreach ($dirList as $key => $value) {
$fileListData['result'][$count]['name'] = $value['folder_name']; $fileListData['result'][$count]['name'] = $value['folder_name'];
$fileListData['result'][$count]['rights'] = "drwxr-xr-x"; $fileListData['result'][$count]['rights'] = "drwxr-xr-x";

@ -301,15 +301,15 @@ class LocalAdapter extends Model{
* @return array * @return array
*/ */
static function getThumbSize($width,$height){ static function getThumbSize($width,$height){
$rate = $width/$height; // $rate = $width/$height;
$maxWidth = 90; // $maxWidth = 280;
$maxHeight = 39; // $maxHeight = 150;
$changeWidth = 39*$rate; // $changeWidth = 150*$rate;
$changeHeight = 90/$rate; // $changeHeight = 280/$rate;
if($changeWidth>=$maxWidth){ // if($changeWidth>=$maxWidth){
return [(int)$changeHeight,90]; // return [(int)$changeHeight,280];
} // }
return [39,(int)$changeWidth]; return [230,200];
} }
/** /**

@ -31,7 +31,10 @@
allowShare:"{$groupData.allow_share}", allowShare:"{$groupData.allow_share}",
allowRemoteDownload:"{:explode(",",$groupData.aria2)[0]}", allowRemoteDownload:"{:explode(",",$groupData.aria2)[0]}",
allowTorrentDownload:"{:explode(",",$groupData.aria2)[1]}", allowTorrentDownload:"{:explode(",",$groupData.aria2)[1]}",
}; };
apiURL={
imgThumb:"/File/Thumb"
};
</script> </script>
</head> </head>
<body> <body>

@ -714,7 +714,7 @@ function QiniuJsSDK() {
logger.debug("get uptoken from: ", that.uptoken_url); logger.debug("get uptoken from: ", that.uptoken_url);
// TODO: use mOxie // TODO: use mOxie
var ajax = that.createAjax(); var ajax = that.createAjax();
ajax.open('GET', that.uptoken_url, false); ajax.open('GET', that.uptoken_url, true);
ajax.setRequestHeader("If-Modified-Since", "0"); ajax.setRequestHeader("If-Modified-Since", "0");
// ajax.onreadystatechange = function() { // ajax.onreadystatechange = function() {
// if (ajax.readyState === 4 && ajax.status === 200) { // if (ajax.readyState === 4 && ajax.status === 200) {
@ -723,58 +723,64 @@ function QiniuJsSDK() {
// } // }
// }; // };
ajax.send(); ajax.send();
if (ajax.status === 200) { ajax.onload = function (e){
var res = that.parseJSON(ajax.responseText); if (ajax.status === 200) {
that.token = res.uptoken; var res = that.parseJSON(ajax.responseText);
if (uploadConfig.saveType == "oss"){ that.token = res.uptoken;
var putPolicy = that.token; if (uploadConfig.saveType == "oss"){
that.sign = res.sign; var putPolicy = that.token;
that.access = res.id; that.sign = res.sign;
that.file_name = res.key; that.access = res.id;
that.callback = res.callback; that.file_name = res.key;
}else if(uploadConfig.saveType == "s3"){ that.callback = res.callback;
var putPolicy = that.token; }else if(uploadConfig.saveType == "s3"){
that.sign = res.sign; var putPolicy = that.token;
that.policy = res.policy; that.sign = res.sign;
that.file_name = res.key; that.policy = res.policy;
that.credential = res.credential; that.file_name = res.key;
that.x_amz_date = res.x_amz_date; that.credential = res.credential;
that.surl = res.siteUrl; that.x_amz_date = res.x_amz_date;
that.callbackKey = res.callBackKey; that.surl = res.siteUrl;
}else if(uploadConfig.saveType == "upyun"){ that.callbackKey = res.callBackKey;
var putPolicy = that.token; }else if(uploadConfig.saveType == "upyun"){
that.token = res.token; var putPolicy = that.token;
that.policy = res.policy; that.token = res.token;
}else if(uploadConfig.saveType == "remote"){ that.policy = res.policy;
var putPolicy = that.token; }else if(uploadConfig.saveType == "remote"){
that.policy = res.uptoken; var putPolicy = that.token;
}else{ that.policy = res.uptoken;
var segments = that.token.split(":"); }else{
var putPolicy = that.parseJSON(that.URLSafeBase64Decode(segments[2])); var segments = that.token.split(":");
if (!that.tokenMap) { var putPolicy = that.parseJSON(that.URLSafeBase64Decode(segments[2]));
that.tokenMap = {}; if (!that.tokenMap) {
} that.tokenMap = {};
var getTimestamp = function(time) {
return Math.ceil(time.getTime()/1000);
};
var serverTime = getTimestamp(new Date(ajax.getResponseHeader("date")));
var clientTime = getTimestamp(new Date());
that.tokenInfo = {
serverDelay: clientTime - serverTime,
deadline: putPolicy.deadline,
isExpired: function() {
var leftTime = this.deadline - getTimestamp(new Date()) + this.serverDelay;
return leftTime < 600;
} }
}; var getTimestamp = function(time) {
logger.debug("get token info: ", that.tokenInfo); return Math.ceil(time.getTime()/1000);
};
var serverTime = getTimestamp(new Date(ajax.getResponseHeader("date")));
var clientTime = getTimestamp(new Date());
that.tokenInfo = {
serverDelay: clientTime - serverTime,
deadline: putPolicy.deadline,
isExpired: function() {
var leftTime = this.deadline - getTimestamp(new Date()) + this.serverDelay;
return leftTime < 600;
}
};
logger.debug("get token info: ", that.tokenInfo);
}
logger.debug("get new uptoken: ", that.token);
} else {
logger.error("get uptoken error: ", ajax.responseText);
} }
}
logger.debug("get new uptoken: ", that.token); ajax.onerror = function (e){
} else {
logger.error("get uptoken error: ", ajax.responseText); logger.error("get uptoken error: ", ajax.responseText);
} }
} else if (op.uptoken_func) { } else if (op.uptoken_func) {
logger.debug("get uptoken from uptoken_func"); logger.debug("get uptoken from uptoken_func");
that.token = op.uptoken_func(file); that.token = op.uptoken_func(file);

Loading…
Cancel
Save