From 2e2357e794e59b17ea58b15033184b2001bf7291 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Fri, 8 Mar 2019 21:27:17 +0800 Subject: [PATCH] Feat: file type filter &Fix: cannot create torrent remote download in onedrive policy --- application/index/controller/File.php | 8 +- .../index/controller/RemoteDownload.php | 4 +- application/index/model/FileManage.php | 76 ++++++++++++++++++- application/index/model/ShareHandler.php | 14 ++-- application/index/view/home/home.html | 2 + static/media/default-skin.b257fa9c.svg | 1 + 6 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 static/media/default-skin.b257fa9c.svg diff --git a/application/index/controller/File.php b/application/index/controller/File.php index 0860c583..6e9fe705 100644 --- a/application/index/controller/File.php +++ b/application/index/controller/File.php @@ -87,9 +87,11 @@ class File extends Controller{ } public function Share(){ - $reqPath = json_decode(file_get_contents("php://input"),true)['item']; - $shareType = json_decode(file_get_contents("php://input"),true)['shareType']; - ShareHandler::createShare($reqPath,$shareType,$this->userObj->getSQLData(),$this->userObj->getGroupData()); + $reqData = json_decode(file_get_contents("php://input"),true); + $reqPath = $reqData['item']; + $shareType = $reqData['shareType']; + $sharePwd = $reqData['pwd']; + ShareHandler::createShare($reqPath,$shareType,$sharePwd,$this->userObj->getSQLData(),$this->userObj->getGroupData()); } public function gerSource(){ diff --git a/application/index/controller/RemoteDownload.php b/application/index/controller/RemoteDownload.php index 6bbe1222..c13d361b 100644 --- a/application/index/controller/RemoteDownload.php +++ b/application/index/controller/RemoteDownload.php @@ -63,8 +63,8 @@ class RemoteDownload extends Controller{ public function AddTorrent(){ $policyData = Db::name("policy")->where("id",$this->userObj->groupData["policy_name"])->find(); - if(!$this->checkPerimission(0) || $policyData["policy_type"] != "local"){ - return json(['error'=>1,'message'=>'您当前的无用户无法执行此操作']); + if(!$this->checkPerimission(0) || $policyData["policy_type"] != "local" && $policyData["policy_type"] != "onedrive"){ + return json(["result"=>['success'=>false,'error'=>"您当前的无用户无法执行此操作"]]); } $downloadingLength = Db::name("download") ->where("owner",$this->userObj->uid) diff --git a/application/index/model/FileManage.php b/application/index/model/FileManage.php index 3df9c72f..8b9f9aac 100644 --- a/application/index/model/FileManage.php +++ b/application/index/model/FileManage.php @@ -542,11 +542,79 @@ class FileManage extends Model{ ])->setDec('used_storage', $size); } + static function filterFile($keyWords,$uid){ + switch ($keyWords) { + case '{filterType:video}': + $fileList = Db::name('files') + ->where('upload_user',$uid) + ->where('orign_name',"like","%.mp4") + ->whereOr('orign_name',"like","%.flv") + ->whereOr('orign_name',"like","%.avi") + ->whereOr('orign_name',"like","%.wmv") + ->whereOr('orign_name',"like","%.mkv") + ->whereOr('orign_name',"like","%.rm") + ->whereOr('orign_name',"like","%.rmvb") + ->whereOr('orign_name',"like","%.mov") + ->whereOr('orign_name',"like","%.ogv") + ->select(); + break; + case '{filterType:audio}': + $fileList = Db::name('files') + ->where('upload_user',$uid) + ->where('orign_name',"like","%.mp3") + ->whereOr('orign_name',"like","%.flac") + ->whereOr('orign_name',"like","%.ape") + ->whereOr('orign_name',"like","%.wav") + ->whereOr('orign_name',"like","%.acc") + ->whereOr('orign_name',"like","%.ogg") + ->select(); + break; + case '{filterType:image}': + $fileList = Db::name('files') + ->where('upload_user',$uid) + ->where('orign_name',"like","%.bmp") + ->whereOr('orign_name',"like","%.flac") + ->whereOr('orign_name',"like","%.iff") + ->whereOr('orign_name',"like","%.png") + ->whereOr('orign_name',"like","%.gif") + ->whereOr('orign_name',"like","%.jpg") + ->whereOr('orign_name',"like","%.jpge") + ->whereOr('orign_name',"like","%.psd") + ->whereOr('orign_name',"like","%.svg") + ->whereOr('orign_name',"like","%.webp") + ->select(); + break; + case '{filterType:doc}': + $fileList = Db::name('files') + ->where('upload_user',$uid) + ->where('orign_name',"like","%.txt") + ->whereOr('orign_name',"like","%.md") + ->whereOr('orign_name',"like","%.pdf") + ->whereOr('orign_name',"like","%.doc") + ->whereOr('orign_name',"like","%.docx") + ->whereOr('orign_name',"like","%.ppt") + ->whereOr('orign_name',"like","%.pptx") + ->whereOr('orign_name',"like","%.xls") + ->whereOr('orign_name',"like","%.xlsx") + ->select(); + break; + default: + $fileList = []; + break; + } + return $fileList; + } + static function searchFile($keyWords,$uid){ - $fileList = Db::name('files') - ->where('upload_user',$uid) - ->where('orign_name',"like","%$keyWords%") - ->select(); + if (0 === strpos($keyWords, '{filterType:')) { + $fileList = self::filterFile($keyWords,$uid); + }else{ + $fileList = Db::name('files') + ->where('upload_user',$uid) + ->where('orign_name',"like","%$keyWords%") + ->select(); + } + $count= 0; $fileListData=[ "result"=>[], diff --git a/application/index/model/ShareHandler.php b/application/index/model/ShareHandler.php index 876c17b9..fb59a8db 100644 --- a/application/index/model/ShareHandler.php +++ b/application/index/model/ShareHandler.php @@ -235,7 +235,7 @@ class ShareHandler extends Model{ } } - static function createShare($fname,$type,$user,$group){ + static function createShare($fname,$type,$pwd,$user,$group){ if(!$group["allow_share"]){ self::setError("您当前的用户组无权分享文件"); } @@ -243,9 +243,9 @@ class ShareHandler extends Model{ $fnameTmp = FileManage::getFileName($fname)[0]; $fileRecord = Db::name('files')->where('upload_user',$user["id"])->where('orign_name',$fnameTmp)->where('dir',$path)->find(); if(empty($fileRecord)){ - self::createDirShare($fname,$type,$user,$group); + self::createDirShare($fname,$type,$pwd,$user,$group); }else{ - self::createFileShare($fileRecord,$type,$user,$group); + self::createFileShare($fileRecord,$type,$pwd,$user,$group); } } @@ -257,13 +257,13 @@ class ShareHandler extends Model{ die('{ "result": "'.$text.'" }'); } - static function createDirShare($fname,$type,$user,$group){ + static function createDirShare($fname,$type,$pwd,$user,$group){ $dirRecord = Db::name('folders')->where('owner',$user["id"])->where('position_absolute',$fname)->find(); if(empty($dirRecord)){ self::setError("目录不存在"); } $shareKey = self::getRandomKey(8); - $sharePwd = $type=="public" ? "0" : self::getRandomKey(6); + $sharePwd = $type=="public" ? "0" : $pwd; $SQLData = [ 'type' => $type=="public" ? "public" : "private", 'share_time' => date("Y-m-d H:i:s"), @@ -285,9 +285,9 @@ class ShareHandler extends Model{ } } - static function createFileShare($file,$type,$user,$group){ + static function createFileShare($file,$type,$pwd,$user,$group){ $shareKey = self::getRandomKey(8); - $sharePwd = $type=="public" ? "0" : self::getRandomKey(6); + $sharePwd = $type=="public" ? "0" : $pwd; $SQLData = [ 'type' => $type=="public" ? "public" : "private", 'share_time' => date("Y-m-d H:i:s"), diff --git a/application/index/view/home/home.html b/application/index/view/home/home.html index 2ac8f159..8a0b3a8e 100644 --- a/application/index/view/home/home.html +++ b/application/index/view/home/home.html @@ -35,6 +35,8 @@ apiURL={ imgThumb:"/File/Thumb", preview:"/File/Preview", + download:"/File/Download", + docPreiview:'/File/DocPreview', }; mediaType = {} diff --git a/static/media/default-skin.b257fa9c.svg b/static/media/default-skin.b257fa9c.svg new file mode 100644 index 00000000..9d5f0c6a --- /dev/null +++ b/static/media/default-skin.b257fa9c.svg @@ -0,0 +1 @@ +default-skin 2 \ No newline at end of file