Feat: Search file api
This commit is contained in:
parent
e0b4b42ec6
commit
c741d79677
3 changed files with 69 additions and 39 deletions
|
@ -27,37 +27,33 @@ class File extends Controller{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [index description]
|
||||
* @Author Aaron
|
||||
* @DateTime 2017-07-03
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function index(){
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* [List description]
|
||||
* @Author Aaron
|
||||
* @DateTime 2017-07-03
|
||||
*/
|
||||
public function ListFile(){
|
||||
$reqPath = stripslashes(json_decode(file_get_contents("php://input"),true)['path']);
|
||||
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(){
|
||||
$reqPath = json_decode(file_get_contents("php://input"),true)['items'];
|
||||
$dirPath = json_decode(file_get_contents("php://input"),true)['dirs'];
|
||||
$reqData = json_decode(file_get_contents("php://input"),true);
|
||||
$reqPath = array_key_exists("dirs",$reqData)?$reqData["items"]:array();
|
||||
$dirPath = array_key_exists("dirs",$reqData)?$reqData["dirs"]:array();
|
||||
FileManage::DirDeleteHandler($dirPath,$this->userObj->uid);
|
||||
return FileManage::DeleteHandler($reqPath,$this->userObj->uid);
|
||||
return json(FileManage::DeleteHandler($reqPath,$this->userObj->uid));
|
||||
}
|
||||
|
||||
public function Move(){
|
||||
$reqPath = json_decode(file_get_contents("php://input"),true)['items'];
|
||||
$dirPath = json_decode(file_get_contents("php://input"),true)['dirs'];
|
||||
$newPath = json_decode(file_get_contents("php://input"),true)['newPath'];
|
||||
$reqData = json_decode(file_get_contents("php://input"),true);
|
||||
$reqPath = array_key_exists("dirs",$reqData)?$reqData["items"]:array();
|
||||
$dirPath = array_key_exists("dirs",$reqData)?$reqData["dirs"]:array();
|
||||
$newPath = $reqData['newPath'];
|
||||
return FileManage::MoveHandler($reqPath,$dirPath,$newPath,$this->userObj->uid);
|
||||
}
|
||||
|
||||
|
|
|
@ -542,6 +542,31 @@ class FileManage extends Model{
|
|||
])->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]
|
||||
* @param [type] $path [description]
|
||||
|
@ -563,6 +588,7 @@ class FileManage extends Model{
|
|||
$fileListData['result'][$count]['name2'] = "";
|
||||
$fileListData['result'][$count]['id'] = $value['id'];
|
||||
$fileListData['result'][$count]['pic'] = "";
|
||||
$fileListData['result'][$count]['path'] = $value['position'];
|
||||
$count++;
|
||||
}
|
||||
foreach ($fileList as $key => $value) {
|
||||
|
@ -574,6 +600,7 @@ class FileManage extends Model{
|
|||
$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++;
|
||||
}
|
||||
|
||||
|
|
|
@ -713,19 +713,22 @@ function QiniuJsSDK() {
|
|||
} else if (op.uptoken_url) {
|
||||
logger.debug("get uptoken from: ", that.uptoken_url);
|
||||
// TODO: use mOxie
|
||||
var ajax = that.createAjax();
|
||||
ajax.open('GET', that.uptoken_url, true);
|
||||
ajax.setRequestHeader("If-Modified-Since", "0");
|
||||
// ajax.onreadystatechange = function() {
|
||||
// if (ajax.readyState === 4 && ajax.status === 200) {
|
||||
// var res = that.parseJSON(ajax.responseText);
|
||||
// that.token = res.uptoken;
|
||||
// }
|
||||
// };
|
||||
ajax.send();
|
||||
ajax.onload = function (e){
|
||||
if (ajax.status === 200) {
|
||||
var res = that.parseJSON(ajax.responseText);
|
||||
// var ajax = that.createAjax();
|
||||
// ajax.open('GET', that.uptoken_url, false);
|
||||
// ajax.setRequestHeader("If-Modified-Since", "0");
|
||||
|
||||
// ajax.send();
|
||||
var ajax = new Promise(function(resolve, reject) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = function() {
|
||||
resolve(xhr);
|
||||
};
|
||||
xhr.onerror = reject;
|
||||
xhr.open('GET', that.uptoken_url);
|
||||
xhr.send();
|
||||
});
|
||||
ajax.then(function(result){
|
||||
var res = that.parseJSON(result.responseText);
|
||||
that.token = res.uptoken;
|
||||
if (uploadConfig.saveType == "oss"){
|
||||
var putPolicy = that.token;
|
||||
|
@ -758,7 +761,7 @@ function QiniuJsSDK() {
|
|||
var getTimestamp = function(time) {
|
||||
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());
|
||||
that.tokenInfo = {
|
||||
serverDelay: clientTime - serverTime,
|
||||
|
@ -770,16 +773,20 @@ function QiniuJsSDK() {
|
|||
};
|
||||
logger.debug("get token info: ", that.tokenInfo);
|
||||
}
|
||||
})
|
||||
// ajax.onload = function (e){
|
||||
// if (ajax.status === 200) {
|
||||
|
||||
logger.debug("get new uptoken: ", that.token);
|
||||
|
||||
// logger.debug("get new uptoken: ", that.token);
|
||||
|
||||
} else {
|
||||
logger.error("get uptoken error: ", ajax.responseText);
|
||||
}
|
||||
}
|
||||
ajax.onerror = function (e){
|
||||
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);
|
||||
// }
|
||||
|
||||
} else if (op.uptoken_func) {
|
||||
logger.debug("get uptoken from uptoken_func");
|
||||
|
|
Loading…
Add table
Reference in a new issue