From c741d7967747227cdff35c0cd348561f41ad2931 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Thu, 7 Mar 2019 15:29:22 +0800 Subject: [PATCH] Feat: Search file api --- application/index/controller/File.php | 30 +++++++-------- application/index/model/FileManage.php | 27 ++++++++++++++ static/js/uploader/qiniu.js | 51 +++++++++++++++----------- 3 files changed, 69 insertions(+), 39 deletions(-) diff --git a/application/index/controller/File.php b/application/index/controller/File.php index c2240979..1ff41fbd 100644 --- a/application/index/controller/File.php +++ b/application/index/controller/File.php @@ -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); } diff --git a/application/index/model/FileManage.php b/application/index/model/FileManage.php index 9f04abcf..44d1b0a2 100644 --- a/application/index/model/FileManage.php +++ b/application/index/model/FileManage.php @@ -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++; } diff --git a/static/js/uploader/qiniu.js b/static/js/uploader/qiniu.js index 21072c57..acb0c67a 100644 --- a/static/js/uploader/qiniu.js +++ b/static/js/uploader/qiniu.js @@ -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");