Feat: Search file api

pull/141/head
HFO4 7 years ago
parent e0b4b42ec6
commit c741d79677

@ -27,37 +27,33 @@ class File extends Controller{
} }
} }
/**
* [index description]
* @Author Aaron
* @DateTime 2017-07-03
* @return [type] [description]
*/
public function index(){ public function index(){
return ""; return "";
} }
/**
* [List description]
* @Author Aaron
* @DateTime 2017-07-03
*/
public function ListFile(){ public function ListFile(){
$reqPath = stripslashes(json_decode(file_get_contents("php://input"),true)['path']); $reqPath = stripslashes(json_decode(file_get_contents("php://input"),true)['path']);
return json(FileManage::ListFile($reqPath,$this->userObj->uid)); return json(FileManage::ListFile($reqPath,$this->userObj->uid));
} }
public function SearchFile(){
$keyWords = stripslashes(json_decode(file_get_contents("php://input"),true)['path']);
return json(FileManage::searchFile($keyWords,$this->userObj->uid));
}
public function Delete(){ public function Delete(){
$reqPath = json_decode(file_get_contents("php://input"),true)['items']; $reqData = json_decode(file_get_contents("php://input"),true);
$dirPath = json_decode(file_get_contents("php://input"),true)['dirs']; $reqPath = array_key_exists("dirs",$reqData)?$reqData["items"]:array();
$dirPath = array_key_exists("dirs",$reqData)?$reqData["dirs"]:array();
FileManage::DirDeleteHandler($dirPath,$this->userObj->uid); FileManage::DirDeleteHandler($dirPath,$this->userObj->uid);
return FileManage::DeleteHandler($reqPath,$this->userObj->uid); return json(FileManage::DeleteHandler($reqPath,$this->userObj->uid));
} }
public function Move(){ public function Move(){
$reqPath = json_decode(file_get_contents("php://input"),true)['items']; $reqData = json_decode(file_get_contents("php://input"),true);
$dirPath = json_decode(file_get_contents("php://input"),true)['dirs']; $reqPath = array_key_exists("dirs",$reqData)?$reqData["items"]:array();
$newPath = json_decode(file_get_contents("php://input"),true)['newPath']; $dirPath = array_key_exists("dirs",$reqData)?$reqData["dirs"]:array();
$newPath = $reqData['newPath'];
return FileManage::MoveHandler($reqPath,$dirPath,$newPath,$this->userObj->uid); return FileManage::MoveHandler($reqPath,$dirPath,$newPath,$this->userObj->uid);
} }

@ -542,6 +542,31 @@ class FileManage extends Model{
])->setDec('used_storage', $size); ])->setDec('used_storage', $size);
} }
static function searchFile($keyWords,$uid){
$fileList = Db::name('files')
->where('upload_user',$uid)
->where('orign_name',"like","%$keyWords%")
->select();
$count= 0;
$fileListData=[
"result"=>[],
];
foreach ($fileList as $key => $value) {
$fileListData['result'][$count]['name'] = $value['orign_name'];
$fileListData['result'][$count]['rights'] = "drwxr-xr-x";
$fileListData['result'][$count]['size'] = $value['size'];
$fileListData['result'][$count]['date'] = $value['upload_date'];
$fileListData['result'][$count]['type'] = 'file';
$fileListData['result'][$count]['name2'] = $value["dir"];
$fileListData['result'][$count]['id'] = $value["id"];
$fileListData['result'][$count]['pic'] = $value["pic_info"];
$fileListData['result'][$count]['path'] = $value['dir'];
$count++;
}
return $fileListData;
}
/** /**
* [List description] * [List description]
* @param [type] $path [description] * @param [type] $path [description]
@ -563,6 +588,7 @@ class FileManage extends Model{
$fileListData['result'][$count]['name2'] = ""; $fileListData['result'][$count]['name2'] = "";
$fileListData['result'][$count]['id'] = $value['id']; $fileListData['result'][$count]['id'] = $value['id'];
$fileListData['result'][$count]['pic'] = ""; $fileListData['result'][$count]['pic'] = "";
$fileListData['result'][$count]['path'] = $value['position'];
$count++; $count++;
} }
foreach ($fileList as $key => $value) { foreach ($fileList as $key => $value) {
@ -574,6 +600,7 @@ class FileManage extends Model{
$fileListData['result'][$count]['name2'] = $value["dir"]; $fileListData['result'][$count]['name2'] = $value["dir"];
$fileListData['result'][$count]['id'] = $value["id"]; $fileListData['result'][$count]['id'] = $value["id"];
$fileListData['result'][$count]['pic'] = $value["pic_info"]; $fileListData['result'][$count]['pic'] = $value["pic_info"];
$fileListData['result'][$count]['path'] = $value['dir'];
$count++; $count++;
} }

@ -713,19 +713,22 @@ function QiniuJsSDK() {
} else if (op.uptoken_url) { } else if (op.uptoken_url) {
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, true); // ajax.open('GET', that.uptoken_url, false);
ajax.setRequestHeader("If-Modified-Since", "0"); // ajax.setRequestHeader("If-Modified-Since", "0");
// ajax.onreadystatechange = function() {
// if (ajax.readyState === 4 && ajax.status === 200) { // ajax.send();
// var res = that.parseJSON(ajax.responseText); var ajax = new Promise(function(resolve, reject) {
// that.token = res.uptoken; var xhr = new XMLHttpRequest();
// } xhr.onload = function() {
// }; resolve(xhr);
ajax.send(); };
ajax.onload = function (e){ xhr.onerror = reject;
if (ajax.status === 200) { xhr.open('GET', that.uptoken_url);
var res = that.parseJSON(ajax.responseText); xhr.send();
});
ajax.then(function(result){
var res = that.parseJSON(result.responseText);
that.token = res.uptoken; that.token = res.uptoken;
if (uploadConfig.saveType == "oss"){ if (uploadConfig.saveType == "oss"){
var putPolicy = that.token; var putPolicy = that.token;
@ -758,7 +761,7 @@ function QiniuJsSDK() {
var getTimestamp = function(time) { var getTimestamp = function(time) {
return Math.ceil(time.getTime()/1000); return Math.ceil(time.getTime()/1000);
}; };
var serverTime = getTimestamp(new Date(ajax.getResponseHeader("date"))); var serverTime = getTimestamp(new Date(result.getResponseHeader("date")));
var clientTime = getTimestamp(new Date()); var clientTime = getTimestamp(new Date());
that.tokenInfo = { that.tokenInfo = {
serverDelay: clientTime - serverTime, serverDelay: clientTime - serverTime,
@ -770,16 +773,20 @@ function QiniuJsSDK() {
}; };
logger.debug("get token info: ", that.tokenInfo); logger.debug("get token info: ", that.tokenInfo);
} }
})
// ajax.onload = function (e){
// if (ajax.status === 200) {
logger.debug("get new uptoken: ", that.token);
} else { // logger.debug("get new uptoken: ", that.token);
logger.error("get uptoken error: ", ajax.responseText);
} // } else {
} // logger.error("get uptoken error: ", ajax.responseText);
ajax.onerror = function (e){ // }
logger.error("get uptoken error: ", ajax.responseText); // }
} // ajax.onerror = function (e){
// 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");

Loading…
Cancel
Save