diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..855b1d7d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.map +composer.lock \ No newline at end of file diff --git a/application/config.php b/application/config.php index 38405e4a..95658562 100644 --- a/application/config.php +++ b/application/config.php @@ -18,7 +18,7 @@ return [ // 应用命名空间 'app_namespace' => 'app', // 应用调试模式 - 'app_debug' => false, + 'app_debug' => true, // 应用Trace 'app_trace' => false, // 应用模式状态 @@ -240,6 +240,12 @@ return [ 'var_page' => 'page', 'list_rows' => 15, ], + + //分片上传大小(只对本地策略有效) + 'upload'=>[ + 'chunk_size' => 10*1024*1024, + ], + // +---------------------------------------------------------------------- // | 验证码设置 // +---------------------------------------------------------------------- diff --git a/application/index/controller/Explore.php b/application/index/controller/Explore.php index 7f1bebe1..f6445190 100644 --- a/application/index/controller/Explore.php +++ b/application/index/controller/Explore.php @@ -14,31 +14,24 @@ class Explore extends Controller{ public $siteOptions; public function _initialize(){ - $this->siteOptions = Option::getValues(["basic"]); } public function Search(){ $this->visitorObj = new User(cookie('user_id'),cookie('login_key')); - return view("search",[ - "options" => $this->siteOptions, - 'loginStatus' => $this->visitorObj->loginStatus, - 'userData' => $this->visitorObj->userSQLData, - ]); - } - - public function S(){ - $this->visitorObj = new User(cookie('user_id'),cookie('login_key')); + $this->siteOptions = Option::getValues(["basic"],$this->visitorObj->userSQLData); $keyWords=input("param.key"); if(empty($keyWords)){ - $this->redirect('/Explore/Search',302); - } - $list = Db::name('shares') + $this->error("搜索词不为空",200,$this->siteOptions); + }else{ + $list = Db::name('shares') ->where('type',"public") ->where('origin_name',"like","%".$keyWords."%") ->order('share_time DESC') - ->paginate(10); - $listData = $list->all(); + ->select(); + } + $listData = $list; foreach ($listData as $key => $value) { + unset($listData[$key]["source_name"]); if($value["source_type"]=="file"){ $listData[$key]["fileData"] = $value["origin_name"]; @@ -50,9 +43,8 @@ class Explore extends Controller{ return view("result",[ "options" => $this->siteOptions, 'loginStatus' => $this->visitorObj->loginStatus, - 'userData' => $this->visitorObj->userSQLData, - 'list' => $listData, - 'listOrigin' => $list, + 'userData' => $this->visitorObj->getInfo(), + 'list' => json_encode($listData), 'keyWords' => $keyWords, ]); } diff --git a/application/index/controller/File.php b/application/index/controller/File.php index eb729005..1c751998 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 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(){ - $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); } @@ -68,7 +64,7 @@ class File extends Controller{ } public function Preview(){ - $reqPath = $_GET["path"]; + $reqPath =$_GET["path"]; $fileObj = new FileManage($reqPath,$this->userObj->uid); $Redirect = $fileObj->PreviewHandler(); if($Redirect[0]){ @@ -78,7 +74,7 @@ class File extends Controller{ public function ListPic(){ $reqPath = $_GET["path"]; - return FileManage::listPic($reqPath,$this->userObj->uid); + return json(FileManage::listPic($reqPath,$this->userObj->uid)); } public function Download(){ @@ -91,19 +87,22 @@ 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(){ - $reqPath = $_POST["path"]; + $reqData = json_decode(file_get_contents("php://input"),true); + $reqPath = $reqData['path']; $fileObj = new FileManage($reqPath,$this->userObj->uid); $FileHandler = $fileObj->Source(); } public function Content(){ - $reqPath = json_decode(file_get_contents("php://input"),true)['item']; + $reqPath = urldecode(input("get.path")); $fileObj = new FileManage($reqPath,$this->userObj->uid); $FileHandler = $fileObj->getContent(); } @@ -170,6 +169,6 @@ class File extends Controller{ } } - return FileManage::createFolder($dirName,$dirPosition,$this->userObj->uid); + return json(FileManage::createFolder($dirName,$dirPosition,$this->userObj->uid)); } } \ No newline at end of file diff --git a/application/index/controller/Home.php b/application/index/controller/Home.php index f73650c0..96c76dd6 100644 --- a/application/index/controller/Home.php +++ b/application/index/controller/Home.php @@ -30,11 +30,13 @@ class Home extends Controller{ } $policyData["max_size"] = $policyData["max_size"]/(1024*1024); return view('home', [ - 'options' => Option::getValues(['basic','upload']), + 'options' => Option::getValues(['basic','upload'],$this->userObj->userSQLData), 'userInfo' => $userInfo, 'extLimit' => $extLimit, 'policyData' => $policyData, 'groupData' => $groupData, + 'chunkSize' => config('upload.chunk_size'), + 'path' => empty(input("get.path"))?"/":input("get.path"), ]); } @@ -42,44 +44,10 @@ class Home extends Controller{ $userInfo = $this->userObj->getInfo(); $groupData = $this->userObj->getGroupData(); return view('download', [ - 'options' => Option::getValues(['basic','group_sell']), + 'options' => Option::getValues(['basic','group_sell'],$this->userObj->userSQLData), 'userInfo' => $userInfo, 'groupData' => $groupData, ]); } - - public function Album(){ - $userInfo = $this->userObj->getInfo(); - $list = Db::name("files")->where("upload_user",$this->userObj->uid) - ->where(function ($query) { - $query->where('orign_name', "like","%jpg") - ->whereor('orign_name', "like","%png") - ->whereor('orign_name', "like","%gif") - ->whereor('orign_name', "like","%bmp"); - }) - ->order('id DESC') - ->paginate(9); - $pageCount = ceil(Db::name("files")->where("upload_user",$this->userObj->uid) - ->where(function ($query) { - $query->where('orign_name', "like","%jpg") - ->whereor('orign_name', "like","%png") - ->whereor('orign_name', "like","%gif") - ->whereor('orign_name', "like","%bmp"); - }) - ->order('id DESC')->count()/9); - $listData = $list->all(); - $pageNow = input("?get.page")?input("get.page"):1; - if($pageNow>$pageCount){ - $this->error('您当前没有上传任何图片',404,Option::getValues(['basic','group_sell'])); - } - return view('album', [ - 'options' => Option::getValues(['basic','group_sell']), - 'userInfo' => $userInfo, - 'list' => $listData, - 'listOrigin' => $list, - 'pageCount' => $pageCount, - 'page' => $pageNow, - ]); - } } diff --git a/application/index/controller/Member.php b/application/index/controller/Member.php index 4fbe7307..f8f09ed4 100644 --- a/application/index/controller/Member.php +++ b/application/index/controller/Member.php @@ -82,13 +82,36 @@ class Member extends Controller{ $this->userObj->getMemory(); } + public function SignUp(){ + $this->userObj = new User(cookie('user_id'),cookie('login_key')); + $this->isLoginStatusCheck(); + return view('login', [ + 'options' => Option::getValues(['basic'],$this->userObj->userSQLData), + 'RegOptions' => Option::getValues(['register','login']), + 'loginStatus' => $this->userObj->loginStatus, + 'pageId' => "register", + ]); + } + + public function FindPwd(){ + $this->userObj = new User(cookie('user_id'),cookie('login_key')); + $this->isLoginStatusCheck(); + return view('login', [ + 'options' => Option::getValues(['basic'],$this->userObj->userSQLData), + 'RegOptions' => Option::getValues(['register','login']), + 'loginStatus' => $this->userObj->loginStatus, + 'pageId' => "resetPwd", + ]); + } + public function LoginForm(){ $this->userObj = new User(cookie('user_id'),cookie('login_key')); $this->isLoginStatusCheck(); return view('login', [ - 'options' => Option::getValues(['basic']), + 'options' => Option::getValues(['basic'],$this->userObj->userSQLData), 'RegOptions' => Option::getValues(['register','login']), 'loginStatus' => $this->userObj->loginStatus, + 'pageId' => "login", ]); } @@ -114,10 +137,11 @@ class Member extends Controller{ public function TwoStep(){ $this->userObj = new User(cookie('user_id'),cookie('login_key')); $this->isLoginStatusCheck(); - return view('two_step', [ - 'options' => Option::getValues(['basic']), + return view('login', [ + 'options' => Option::getValues(['basic'],$this->userObj->userSQLData), 'RegOptions' => Option::getValues(['register','login']), 'loginStatus' => $this->userObj->loginStatus, + 'pageId' => "TwoStep", ]); } @@ -133,14 +157,16 @@ class Member extends Controller{ public function emailActivate(){ $activationKey = input('param.key'); - $basicOptions = Option::getValues(['basic']); $this->userObj = new User(cookie('user_id'),cookie('login_key')); $this->isLoginStatusCheck(); + $basicOptions = Option::getValues(['basic','register','login'],$this->userObj->userSQLData); $activeAction = User::activicateUser($activationKey); if($activeAction[0]){ - return view('active_user', [ + return view('login', [ 'options' => $basicOptions, + 'RegOptions' => $basicOptions, 'loginStatus' => $this->userObj->loginStatus, + 'pageId' => "emailActivate", ]); }else{ $this->error($activeAction[1],403,$basicOptions); @@ -150,15 +176,17 @@ class Member extends Controller{ public function resetPwd(){ $resetKey = input('param.key'); $userId = input('get.uid'); - $basicOptions = Option::getValues(['basic']); $this->userObj = new User(cookie('user_id'),cookie('login_key')); + $basicOptions = Option::getValues(['basic','register','login'],$this->userObj->userSQLData); $this->isLoginStatusCheck(); $resetAction = User::resetUser($resetKey,$userId); if($resetAction[0]){ - return view('reset_user', [ + return view('login', [ 'options' => $basicOptions, + 'RegOptions' => $basicOptions, 'loginStatus' => $this->userObj->loginStatus, 'key' => $resetKey."_".$userId, + 'pageId' => "resetPwdForm", ]); }else{ $this->error($resetAction[1],403,$basicOptions); @@ -185,7 +213,7 @@ class Member extends Controller{ $policyList[$key] = $value; } $avaliablePolicy = Db::name("policy")->where("id","in",$policyList)->select(); - $basicOptions = Option::getValues(['basic']); + $basicOptions = Option::getValues(['basic'],$this->userObj->userSQLData); return view('setting', [ 'options' => $basicOptions, 'userInfo' => $userInfo, @@ -236,6 +264,17 @@ class Member extends Controller{ } } + public function ChangeThemeColor(){ + $this->userObj = new User(cookie('user_id'),cookie('login_key')); + $this->loginStatusCheck(); + $saveAction = $this->userObj->changeOption("preferTheme",input("post.theme")); + if($saveAction[0]){ + return json(['error' => '200','msg' => '设置成功']); + }else{ + return json(['error' => '1','msg' => $saveAction[1]]); + } + } + public function HomePage(){ $this->userObj = new User(cookie('user_id'),cookie('login_key')); $userInfo = $this->userObj->getInfo(); diff --git a/application/index/controller/Profile.php b/application/index/controller/Profile.php index 458d78df..ff9a77c3 100644 --- a/application/index/controller/Profile.php +++ b/application/index/controller/Profile.php @@ -14,47 +14,46 @@ class Profile extends Controller{ public $siteOptions; public function _initialize(){ - $this->siteOptions = Option::getValues(["basic"]); } - public function index(){ - $this->visitorObj = new User(cookie('user_id'),cookie('login_key')); - $userId = (string)input("param.uid"); + public function getList(){ + $userId = (string)input("post.uid"); $userData = Db::name("users")->where("id",$userId)->find(); + $page = (int)input("post.page"); if (empty($userId) || empty($userData) || $userData["profile"] == 0){ - $this->error('用户主页不存或者用户关闭了个人主页',404,$this->siteOptions); - } - $groupData = Db::name("groups")->where("id",$userData["user_group"])->find(); - $shareCount = Db::name('shares') - ->where('owner',$userId) - ->where('type',"public") - ->count(); - $regDays = (int)((time()-strtotime($userData["user_date"]))/86400); - switch (input("get.type")) { + $this->error('用户主页不存或者用户关闭了个人主页',404,$this->siteOptions); + } + switch (input("post.type")) { case 'all': $list = Db::name('shares') ->where('owner',$userId) ->where('type',"public") ->order('share_time DESC') - ->paginate(10); + ->page($page.',10') + ->select(); break; case 'hot': $num = Option::getValue("hot_share_num"); $list = Db::name('shares') ->where('owner',$userId) ->where('type',"public") - ->paginate($num); + ->order('download_num DESC') + ->limit($num) + ->select(); break; default: $list = Db::name('shares') ->where('owner',$userId) ->where('type',"public") ->order('share_time DESC') - ->paginate(10); + ->page($page.',10') + ->select(); break; } - $listData = $list->all(); + $listData = $list; foreach ($listData as $key => $value) { + unset($listData[$key]["share_pwd"]); + unset($listData[$key]["source_name"]); if($value["source_type"]=="file"){ $listData[$key]["fileData"] = Db::name('files')->where('id',$value["source_name"])->find()["orign_name"]; @@ -63,14 +62,34 @@ class Profile extends Controller{ $listData[$key]["fileData"] = end($pathDir); } } + + return json($listData); + + + } + + public function index(){ + $this->visitorObj = new User(cookie('user_id'),cookie('login_key')); + $this->siteOptions = Option::getValues(["basic"],$this->visitorObj->userSQLData); + $userId = (string)input("param.uid"); + $userData = Db::name("users")->where("id",$userId)->find(); + if (empty($userId) || empty($userData) || $userData["profile"] == 0){ + $this->error('用户主页不存或者用户关闭了个人主页',404,$this->siteOptions); + } + $groupData = Db::name("groups")->where("id",$userData["user_group"])->find(); + $shareCount = Db::name('shares') + ->where('owner',$userId) + ->where('type',"public") + ->count(); + $regDays = (int)((time()-strtotime($userData["user_date"]))/86400); + return view("profile",[ "options" => $this->siteOptions, 'loginStatus' => $this->visitorObj->loginStatus, - 'userInfo' => $userData, - 'userData' => $this->visitorObj->userSQLData, + 'targetUserInfo' => $userData, + 'userSQL' => $this->visitorObj->userSQLData, + 'userInfo' => $this->visitorObj->getInfo(), 'groupData' => $groupData, - 'list' => $listData, - 'listOrigin' => $list, 'type' => input("get.type"), 'shareCount' => $shareCount, 'regDays' => $regDays, 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/controller/Share.php b/application/index/controller/Share.php index 61733de7..71fc98c4 100644 --- a/application/index/controller/Share.php +++ b/application/index/controller/Share.php @@ -16,7 +16,7 @@ class Share extends Controller{ public function _initialize(){ $this->userObj = new User(cookie('user_id'),cookie('login_key')); - $this->siteOptions = Option::getValues(["basic"]); + $this->siteOptions = Option::getValues(["basic","share"]); } public function index(){ @@ -30,34 +30,36 @@ class Share extends Controller{ $shareObj->numIncrease("view_num"); if($shareObj->shareData["source_type"] == "dir"){ return view('share_dir', [ - 'options' => Option::getValues(['basic','share']), + 'options' => Option::getValues(['basic','share'],$this->userObj->userSQLData), 'userInfo' => $shareObj->shareOwner->userSQLData, 'dirData' => $shareObj->dirData, 'shareData' => $shareObj->shareData, 'loginStatus' => $this->userObj->loginStatus, - 'userData' => $this->userObj->userSQLData, + 'userData' => $this->userObj->getInfo(), 'groupData' => $shareObj->shareOwner->groupData, 'allowPreview' => Option::getValue("allowdVisitorDownload"), + 'path' => empty(input("get.path"))?"/":input("get.path"), ]); }else{ return view('share_single', [ - 'options' => Option::getValues(['basic','share']), + 'options' => Option::getValues(['basic','share'],$this->userObj->userSQLData), 'userInfo' => $shareObj->shareOwner->userSQLData, 'fileData' => $shareObj->fileData, 'shareData' => $shareObj->shareData, 'loginStatus' => $this->userObj->loginStatus, - 'userData' => $this->userObj->userSQLData, + 'userData' => $this->userObj->getInfo(), 'allowPreview' => Option::getValue("allowdVisitorDownload"), + 'path' => empty(input("get.path"))?"/":input("get.path"), ]); } }else{ return view('share_lock', [ - 'options' => Option::getValues(['basic','share']), + 'options' => Option::getValues(['basic','share'],$this->userObj->userSQLData), 'userInfo' => $shareObj->shareOwner->userSQLData, 'fileData' => $shareObj->fileData, 'shareData' => $shareObj->shareData, 'loginStatus' => $this->userObj->loginStatus, - 'userData' => $this->userObj->userSQLData, + 'userData' => $this->userObj->getInfo(), 'pwd' => input("?get.pwd") ? input("get.pwd") : "", ]); } @@ -66,12 +68,18 @@ class Share extends Controller{ public function getDownloadUrl(){ $shareId = input('key'); $shareObj = new ShareHandler($shareId,false); - return $shareObj->getDownloadUrl($this->userObj); + return json($shareObj->getDownloadUrl($this->userObj)); } public function Download(){ $shareId = input('param.key'); $filePath = input('get.path'); + if($this->siteOptions["refererCheck"]=="true"){ + $check = $this->referCheck(); + if(!$check){ + $this->error("来源非法",403,$this->siteOptions); + } + } $shareObj = new ShareHandler($shareId,false); if(empty($filePath)){ $DownloadHandler = $shareObj->Download($this->userObj); @@ -85,6 +93,26 @@ class Share extends Controller{ } } + public function Content(){ + $shareId = input('param.key'); + $filePath = input('get.path'); + if($this->siteOptions["refererCheck"]=="true"){ + $check = $this->referCheck(); + if(!$check){ + $this->error("来源非法",403,$this->siteOptions); + } + } + $shareObj = new ShareHandler($shareId,false); + if(empty($filePath)){ + $contentHandller = $shareObj->getContent($this->userObj,$filePath,false); + }else{ + $contentHandller = $shareObj->getContent($this->userObj,$filePath,true); + } + if(!$contentHandller[0]){ + return json(["result"=>["success"=>false,"error"=>$contentHandller[1]]]); + } + } + public function chekPwd(){ $shareId = input('key'); $inputPwd = input('password'); @@ -95,12 +123,26 @@ class Share extends Controller{ "msg" => "分享不存在" ); } - return $shareObj->checkPwd($inputPwd); + return json($shareObj->checkPwd($inputPwd)); + } + + private function referCheck(){ + $agent = Request::instance()->header('referer'); + if(substr($agent, 0, strlen($this->siteOptions["siteURL"])) !== $this->siteOptions["siteURL"]){ + return false; + } + return true; } public function Preview(){ $shareId = input('param.key'); $filePath = input('get.path'); + if($this->siteOptions["refererCheck"]=="true"){ + $check = $this->referCheck(); + if(!$check){ + $this->error("来源非法",403,$this->siteOptions); + } + } $shareObj = new ShareHandler($shareId,false); if(empty($filePath)){ $previewHandler = $shareObj->Preview($this->userObj); @@ -122,7 +164,7 @@ class Share extends Controller{ $shareId = input('param.key'); $reqPathTo = stripslashes(json_decode(file_get_contents("php://input"),true)['path']); $shareObj = new ShareHandler($shareId,false); - return $shareObj->ListFile($reqPathTo); + return json($shareObj->ListFile($reqPathTo)); } public function ListPic(){ @@ -133,11 +175,17 @@ class Share extends Controller{ } public function Thumb(){ - $shareId = input('get.shareKey'); - $filePath = input('get.path'); + $shareId = input('param.key'); + $filePath = urldecode(input('get.path')); if(input("get.isImg") != "true"){ return ""; } + if($this->siteOptions["refererCheck"]=="true"){ + $check = $this->referCheck(); + if(!$check){ + $this->error("来源非法",403,$this->siteOptions); + } + } $shareObj = new ShareHandler($shareId,false); $Redirect = $shareObj->getThumb($this->userObj,$filePath); if($Redirect[0]){ @@ -147,40 +195,66 @@ class Share extends Controller{ } } + public function DocPreview(){ + $shareId = input('param.key'); + $filePath = urldecode(input('get.path')); + if($this->siteOptions["refererCheck"]=="true"){ + $check = $this->referCheck(); + if(!$check){ + $this->error("来源非法",403,$this->siteOptions); + } + } + $shareObj = new ShareHandler($shareId,false); + if(empty($filePath)){ + $Redirect = $shareObj->getDocPreview($this->userObj,$filePath,false); + }else{ + $Redirect = $shareObj->getDocPreview($this->userObj,$filePath,true); + } + + if($Redirect[0]){ + $this->redirect($Redirect[1],302); + }else{ + $this->error($Redirect[1],403,$this->siteOptions); + } + } + public function Delete(){ $shareId = input('post.id'); $shareObj = new ShareHandler($shareId,false); if(!$shareObj->querryStatus){ - return array( + return json(array( "error" => 1, "msg" => "分享不存在" - ); + )); } - return $shareObj->deleteShare($this->userObj->uid); + return json($shareObj->deleteShare($this->userObj->uid)); } public function ChangePromission(){ $shareId = input('post.id'); $shareObj = new ShareHandler($shareId,false); if(!$shareObj->querryStatus){ - return array( + return json(array( "error" => 1, "msg" => "分享不存在" - ); + )); } - return $shareObj->changePromission($this->userObj->uid); + return json($shareObj->changePromission($this->userObj->uid)); } - public function My(){ + public function ListMyShare(){ if(!$this->userObj->loginStatus){ $this->redirect(url('/Login','','')); exit(); } - $userInfo = $this->userObj->getInfo(); - $groupData = $this->userObj->getGroupData(); - $list = Db::name('shares')->where('owner',$this->userObj->uid)->order('share_time DESC')->paginate(30); - $listData = $list->all(); + $list = Db::name('shares') + ->where('owner',$this->userObj->uid) + ->order('share_time DESC') + ->page(input("post.page").",18") + ->select(); + $listData = $list; foreach ($listData as $key => $value) { + unset($listData[$key]["source_name"]); if($value["source_type"]=="file"){ $listData[$key]["fileData"] = Db::name('files')->where('id',$value["source_name"])->find()["orign_name"]; @@ -188,12 +262,20 @@ class Share extends Controller{ $listData[$key]["fileData"] = $value["source_name"]; } } + return json($listData); + } + + public function My(){ + if(!$this->userObj->loginStatus){ + $this->redirect(url('/Login','','')); + exit(); + } + $userInfo = $this->userObj->getInfo(); + $groupData = $this->userObj->getGroupData(); return view('share_home', [ - 'options' => Option::getValues(['basic','share']), - 'userInfo' => $userInfo, + 'options' => Option::getValues(['basic','share'],$this->userObj->userSQLData), + 'userData' => $userInfo, 'groupData' => $groupData, - 'list' => $listData, - 'listOrigin' => $list ]); } diff --git a/application/index/controller/Viewer.php b/application/index/controller/Viewer.php new file mode 100644 index 00000000..edbcad29 --- /dev/null +++ b/application/index/controller/Viewer.php @@ -0,0 +1,69 @@ +userObj = new User(cookie('user_id'),cookie('login_key')); + // if(!$this->userObj->loginStatus){ + // $this->redirect(url('/Login','','')); + // exit(); + // } + $this->userObj = new User(cookie('user_id'),cookie('login_key')); + } + + public function Video(){ + $path = input("get.path"); + $pathSplit = explode("/",urldecode($path)); + $userInfo = $this->userObj->getInfo(); + $groupData = $this->userObj->getGroupData(); + $url = "/File/Preview?action=preview&path=".$path; + if(input("get.share")==true){ + $url = "/Share/Preview/".input("get.shareKey")."/?path=".$path; + }else if(input("get.single")==true){ + $url = "/Share/Preview/".input("get.shareKey"); + } + return view('video', [ + 'options' => Option::getValues(['basic'],$this->userObj->userSQLData), + 'userInfo' => $userInfo, + 'groupData' => $groupData, + 'url' => $url, + 'fileName' => end($pathSplit), + 'isSharePage' => input("?get.share")?"true":"false", + ]); + } + + public function Markdown(){ + $path = input("get.path"); + $pathSplit = explode("/",urldecode($path)); + $userInfo = $this->userObj->getInfo(); + $groupData = $this->userObj->getGroupData(); + $url = "/File/Content?action=preview&path=".$path; + if(input("get.share")==true){ + $url = "/Share/Content/".input("get.shareKey")."/?path=".$path; + }else if(input("get.single")==true){ + $url = "/Share/Content/".input("get.shareKey"); + } + return view('markdown', [ + 'options' => Option::getValues(['basic'],$this->userObj->userSQLData), + 'userInfo' => $userInfo, + 'groupData' => $groupData, + 'url' => $url, + 'fileName' => end($pathSplit), + 'path' => urldecode($path), + 'isSharePage' => input("?get.share")?"true":"false", + ]); + } + + +} diff --git a/application/index/model/Aria2.php b/application/index/model/Aria2.php index ddc556cd..f641f64b 100644 --- a/application/index/model/Aria2.php +++ b/application/index/model/Aria2.php @@ -341,8 +341,18 @@ class Aria2 extends Model{ $this->removeDownloadResult($sqlData["pid"],$sqlData); if($delete){ if(isset($quenInfo["files"][$sqlData["file_index"]]["path"]) && file_exists($quenInfo["files"][$sqlData["file_index"]]["path"])){ - @unlink($quenInfo["files"][$sqlData["file_index"]]["path"]); + $deleteAction = @unlink($quenInfo["files"][$sqlData["file_index"]]["path"]); @self::remove_directory(dirname($quenInfo["files"][$sqlData["file_index"]]["path"])); + if(file_exists(dirname($quenInfo["files"][$sqlData["file_index"]]["path"]))){ + $task = new Task(); + $task->taskName = "Delete remote download temp file"; + $task->taskType = "deleteFolder"; + $task->taskContent = json_encode([ + "folder" => dirname($quenInfo["files"][$sqlData["file_index"]]["path"]), + ]); + $task->userId = $this->uid; + $task->saveTask(); + } } } Db::name("download")->where("id",$sqlData["id"])->update([ diff --git a/application/index/model/Avatar.php b/application/index/model/Avatar.php index 2eee3cbb..c889fb34 100644 --- a/application/index/model/Avatar.php +++ b/application/index/model/Avatar.php @@ -20,7 +20,7 @@ class Avatar extends Model{ if(!$new){ $userData = Db::name("users")->where('id',$obj)->find(); $this->userData = $userData; - if($userData["avatar"] == "default"){ + if(empty($userData)||$userData["avatar"] == "default"){ $this->avatarType = "default"; }else{ $avatarPrarm = explode(".",$userData["avatar"]); diff --git a/application/index/model/CallbackHandler.php b/application/index/model/CallbackHandler.php index ef658ab2..1b982e85 100644 --- a/application/index/model/CallbackHandler.php +++ b/application/index/model/CallbackHandler.php @@ -120,6 +120,7 @@ class CallbackHandler extends Model{ if(empty($CallbackSqlData)){ $this->setError("Undelegated Request",false,true); } + Db::name('callback')->where('callback_key',$key)->delete(); $this->policyData = Db::name('policy')->where('id',$CallbackSqlData['pid'])->find(); $this->userData = Db::name('users')->where('id',$CallbackSqlData['uid'])->find(); $paths = explode("/",$this->CallbackData["key"]); @@ -135,7 +136,7 @@ class CallbackHandler extends Model{ if(!$jsonData["fsize"]){ $this->setError("File not exist",false,true); } - $jsonData["fsize"] = $jsonData["fsize"]["size"]; + $jsonData["fsize"] = $jsonData["fsize"]; $picInfo = ""; $addAction = FileManage::addFile($jsonData,$this->policyData,$this->userData["id"],""); if(!$addAction[0]){ @@ -147,14 +148,25 @@ class CallbackHandler extends Model{ } private function getS3FileInfo(){ - $s3 = new \S3\S3($this->policyData["ak"], $this->policyData["sk"],false,$this->policyData["op_pwd"]); - $s3->setSignatureVersion('v4'); + $s3 = new \Aws\S3\S3Client([ + 'version' => 'latest', + 'region' => $this->policyData["op_name"], + 'endpoint' => $this->policyData["op_pwd"], + 'use_path_style_endpoint' => true, + 'credentials' => [ + 'key' => $this->policyData["ak"], + 'secret' => $this->policyData["sk"], + ], + ]); try { - $returnVal = $s3->getObjectInfo($this->policyData["bucketname"],$this->CallbackData["key"]); + $returnVal = $s3->headObject([ + 'Bucket'=>$this->policyData["bucketname"], + 'Key'=>$this->CallbackData["key"] + ]); } catch (Exception $e) { return false; } - return $returnVal; + return $returnVal["ContentLength"]; } public function setSuccess($fname){ diff --git a/application/index/model/CronHandler.php b/application/index/model/CronHandler.php index d33062f5..25f95b14 100644 --- a/application/index/model/CronHandler.php +++ b/application/index/model/CronHandler.php @@ -52,6 +52,11 @@ class CronHandler extends Model{ $this->flushOnedriveToken($value["interval_s"]); } break; + case 'delete_remote_downloader_failed_folder': + if($this->checkInterval($value["interval_s"],$value["last_excute"])){ + $this->deleteRemoteDownloaderFailedFolder($value["interval_s"]); + } + break; default: # code... break; @@ -97,6 +102,52 @@ class CronHandler extends Model{ $this->setComplete("flush_aria2"); } + public function deleteRemoteDownloaderFailedFolder($interval){ + echo("flushOnedriveToken..."); + $toBeDeleted = Db::name("task") + ->where("type","deleteFolder") + ->where("status","todo") + ->select(); + $success=[]; + $todo = []; + foreach ($toBeDeleted as $key => $value) { + $attr = json_decode($value["attr"],true); + if(file_exists($attr["folder"])){ + self::remove_directory($attr["folder"]); + } + if(file_exists($attr["folder"])){ + $todo[] = $value["id"]; + }else{ + $success[] = $value["id"]; + } + } + + Db::name("task")->where("id","in",$success)->update(["status"=>"success"]); + + } + + /** + * 移除整个目录 + * + * @param string $dir + * @return void + */ + static function remove_directory($dir){ + if($handle=opendir("$dir")){ + while(false!==($item=readdir($handle))){ + if($item!="."&&$item!=".."){ + if(is_dir("$dir/$item")){ + self::remove_directory("$dir/$item"); + }else{ + unlink("$dir/$item"); + } + } + } + closedir($handle); + rmdir($dir); + } + } + public function flushOnedriveToken($interval){ echo("flushOnedriveToken..."); $toBeFlushedPolicy = Db::name("policy")->where("policy_type","onedrive")->select(); diff --git a/application/index/model/FileManage.php b/application/index/model/FileManage.php index 45c5ff51..473d6ca4 100644 --- a/application/index/model/FileManage.php +++ b/application/index/model/FileManage.php @@ -160,12 +160,19 @@ class FileManage extends Model{ $originFolder = $fname; $new = str_replace("/", "", self::getFileName($new)[0]); if(!$notEcho){ - $new = str_replace(" ", "", $new); + $newToBeVerify = str_replace(" ", "", $new); + } + //检查是否全为空格 + $varifyExplode = explode(".",$newToBeVerify); + $isFullBlackspace = false; + foreach ($varifyExplode as $key => $value) { + if($value == ""){ + $isFullBlackspace = true; + break; + } } - $newSuffix = explode(".",$new); - // 文件名带有‘.’会导致验证失败 - $newPrefix = str_replace($newSuffix, "", $new); - if(!self::fileNameValidate($newPrefix)){ + $toBeValidated = str_replace(".","",$newToBeVerify); + if(!self::fileNameValidate($toBeValidated) || $isFullBlackspace){ if($notEcho){ return '{ "result": { "success": false, "error": "文件名只支持汉字、字母、数字和下划线_及破折号-" } }'; } @@ -184,6 +191,7 @@ class FileManage extends Model{ self::folderRename($originFolder,$folderTmp,$uid,$notEcho); die(); } + $newSuffix = explode(".",$new); $originSuffix = explode(".",$fileRecord["orign_name"]); if(end($originSuffix) != end($newSuffix)){ if($notEcho){ @@ -534,16 +542,114 @@ 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){ + 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"=>[], + ]; + 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] - * @param [type] $uid [description] + * 列出文件 + * + * @param 路径 $path + * @param 用户UID $uid + * @param boolean $isShare 是否为分享模式下列出文件 + * @return void */ - static function ListFile($path,$uid){ + static function ListFile($path,$uid,$isShare=false,$originPath=null){ $fileList = Db::name('files')->where('upload_user',$uid)->where('dir',$path)->select(); $dirList = Db::name('folders')->where('owner',$uid)->where('position',$path)->select(); $count= 0; - $fileListData=[]; + $fileListData=[ + "result"=>[], + ]; foreach ($dirList as $key => $value) { $fileListData['result'][$count]['name'] = $value['folder_name']; $fileListData['result'][$count]['rights'] = "drwxr-xr-x"; @@ -553,6 +659,13 @@ class FileManage extends Model{ $fileListData['result'][$count]['name2'] = ""; $fileListData['result'][$count]['id'] = $value['id']; $fileListData['result'][$count]['pic'] = ""; + $fileListData['result'][$count]['path'] = $value['position']; + if($isShare){ + if (substr($value['position'], 0, strlen($originPath)) == $originPath) { + $value['position'] = substr($value['position'], strlen($originPath)); + } + $fileListData['result'][$count]['path'] = ($value['position']=="")?"/":$value['position']; + } $count++; } foreach ($fileList as $key => $value) { @@ -561,9 +674,15 @@ class FileManage extends Model{ $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']; + if($isShare){ + if (substr($value['dir'], 0, strlen($originPath)) == $originPath) { + $value['dir'] = substr($value['dir'], strlen($originPath)); + } + $fileListData['result'][$count]['path'] = ($value['dir']=="")?"/":$value['dir']; + } $count++; } @@ -585,20 +704,20 @@ class FileManage extends Model{ foreach ($fileList as $key => $value) { if($value["orign_name"] == $firstPreview[0]){ $previewPicInfo = explode(",",$value["pic_info"]); - $previewSrc = $url."action=preview&path=".$path."/".$value["orign_name"]; + $previewSrc = $url."action=preview&path=".urlencode($path."/".$value["orign_name"]); }else{ $picInfo = explode(",",$value["pic_info"]); $fileListData[$count]['src'] = $url."action=preview&path=".$path."/".$value["orign_name"]; - $fileListData[$count]['w'] = $picInfo[0]; - $fileListData[$count]['h'] = $picInfo[1]; + $fileListData[$count]['w'] = 0; + $fileListData[$count]['h'] = 0; $fileListData[$count]['title'] = $value["orign_name"]; $count++; } } array_unshift($fileListData,array( 'src' => $previewSrc, - 'w' => $previewPicInfo[0], - 'h' => $previewPicInfo[1], + 'w' => 0, + 'h' => 0, 'title' => $firstPreview[0], )); return $fileListData; diff --git a/application/index/model/LocalAdapter.php b/application/index/model/LocalAdapter.php index e328ec3f..01d3564b 100644 --- a/application/index/model/LocalAdapter.php +++ b/application/index/model/LocalAdapter.php @@ -301,15 +301,15 @@ class LocalAdapter extends Model{ * @return array */ static function getThumbSize($width,$height){ - $rate = $width/$height; - $maxWidth = 90; - $maxHeight = 39; - $changeWidth = 39*$rate; - $changeHeight = 90/$rate; - if($changeWidth>=$maxWidth){ - return [(int)$changeHeight,90]; - } - return [39,(int)$changeWidth]; + // $rate = $width/$height; + // $maxWidth = 280; + // $maxHeight = 150; + // $changeWidth = 150*$rate; + // $changeHeight = 280/$rate; + // if($changeWidth>=$maxWidth){ + // return [(int)$changeHeight,280]; + // } + return [230,200]; } /** diff --git a/application/index/model/Option.php b/application/index/model/Option.php index b85836d5..e2d42c9f 100644 --- a/application/index/model/Option.php +++ b/application/index/model/Option.php @@ -5,10 +5,27 @@ use think\Model; use think\Db; class Option extends Model{ - static function getValues($groups = ['basic']){ + static function getValues($groups = ['basic'],$userInfo=null){ $t = Db::name('options')->where('option_type','in',$groups)->column('option_value','option_name'); + if(in_array("basic",$groups)){ + return array_merge($t,self::getThemeOptions($t,$userInfo)); + } return $t; } + + static function getThemeOptions($basicOptions,$userInfo){ + $themes = json_decode($basicOptions["themes"],true); + if($userInfo==null){ + return ["themeColor"=>$basicOptions["defaultTheme"],"themeConfig"=>$themes[$basicOptions["defaultTheme"]]]; + }else{ + $userOptions = json_decode($userInfo["options"],true); + if(empty($userOptions)||!array_key_exists("preferTheme",$userOptions)||!array_key_exists($userOptions["preferTheme"],$themes)){ + return ["themeColor"=>$basicOptions["defaultTheme"],"themeConfig"=>$themes[$basicOptions["defaultTheme"]]]; + } + return ["themeColor"=>$userOptions["preferTheme"],"themeConfig"=>$themes[$userOptions["preferTheme"]]]; + } + } + static function getValue($optionName){ return Db::name('options')->where('option_name',$optionName)->value('option_value'); } diff --git a/application/index/model/S3Adapter.php b/application/index/model/S3Adapter.php index b9c7a3c0..184c43da 100644 --- a/application/index/model/S3Adapter.php +++ b/application/index/model/S3Adapter.php @@ -4,9 +4,6 @@ namespace app\index\model; use think\Model; use think\Db; -use Upyun\Upyun; -use Upyun\Config; - use \app\index\model\Option; /** @@ -42,8 +39,25 @@ class S3Adapter extends Model{ if($base===true || $base ===false){ $base = null; } + $s3 = new \Aws\S3\S3Client([ + 'version' => 'latest', + 'region' => $this->policyModel["op_name"], + 'endpoint' => $this->policyModel["op_pwd"], + 'use_path_style_endpoint' => true, + 'credentials' => [ + 'key' => $this->policyModel["ak"], + 'secret' => $this->policyModel["sk"], + ], + ]); + $cmd = $s3->getCommand('GetObject', [ + 'Bucket' => $this->policyModel["bucketname"], + 'Key' => $this->fileModel["pre_name"], + ]); $timeOut = Option::getValue("timeout"); - return [1,\S3\S3::aws_s3_link($this->policyModel["ak"], $this->policyModel["sk"],$this->policyModel["bucketname"],"/".$this->fileModel["pre_name"],3600,$this->policyModel["op_name"])]; + $req = $s3->createPresignedRequest($cmd, '+'.($timeOut/60).' minutes'); + $url = (string)$req->getUri(); + + return [1,$url]; } /** @@ -53,9 +67,21 @@ class S3Adapter extends Model{ * @return void */ public function saveContent($content){ - $s3 = new \S3\S3($this->policyModel["ak"], $this->policyModel["sk"],false,$this->policyModel["op_pwd"]); - $s3->setSignatureVersion('v4'); - $s3->putObjectString($content, $this->policyModel["bucketname"], $this->fileModel["pre_name"]); + $s3 = new \Aws\S3\S3Client([ + 'version' => 'latest', + 'region' => $this->policyModel["op_name"], + 'endpoint' => $this->policyModel["op_pwd"], + 'use_path_style_endpoint' => true, + 'credentials' => [ + 'key' => $this->policyModel["ak"], + 'secret' => $this->policyModel["sk"], + ], + ]); + $s3->putObject([ + 'Bucket' => $this->policyModel["bucketname"], + 'Key' => $this->fileModel["pre_name"], + 'Body' => $content, + ]); } /** @@ -78,7 +104,26 @@ class S3Adapter extends Model{ */ public function Download(){ $timeOut = Option::getValue("timeout"); - return [1,\S3\S3::aws_s3_link($this->policyModel["ak"], $this->policyModel["sk"],$this->policyModel["bucketname"],"/".$this->fileModel["pre_name"],3600,$this->policyModel["op_name"],array(),false)]; + $s3 = new \Aws\S3\S3Client([ + 'version' => 'latest', + 'region' => $this->policyModel["op_name"], + 'endpoint' => $this->policyModel["op_pwd"], + 'use_path_style_endpoint' => true, + 'credentials' => [ + 'key' => $this->policyModel["ak"], + 'secret' => $this->policyModel["sk"], + ], + ]); + $cmd = $s3->getCommand('GetObject', [ + 'Bucket' => $this->policyModel["bucketname"], + 'Key' => $this->fileModel["pre_name"], + 'ResponseContentDisposition' => 'attachment; filename='.$this->fileModel["orign_name"], + ]); + $timeOut = Option::getValue("timeout"); + $req = $s3->createPresignedRequest($cmd, '+'.($timeOut/60).' minutes'); + $url = (string)$req->getUri(); + + return [1,$url]; } /** @@ -89,9 +134,21 @@ class S3Adapter extends Model{ * @return boolean */ static function deleteS3File($fname,$policy){ - $s3 = new \S3\S3($policy["ak"], $policy["sk"],false,$policy["op_pwd"]); - $s3->setSignatureVersion('v4'); - return $s3->deleteObject($policy["bucketname"],$fname); + $s3 = new \Aws\S3\S3Client([ + 'version' => 'latest', + 'region' => $policy["op_name"], + 'endpoint' => $policy["op_pwd"], + 'use_path_style_endpoint' => true, + 'credentials' => [ + 'key' => $policy["ak"], + 'secret' => $policy["sk"], + ], + ]); + $result = $s3->deleteObject([ + 'Bucket' => $policy["bucketname"], + 'Key' => $fname, + ]); + return $result["DeleteMarker"]; } /** diff --git a/application/index/model/ShareHandler.php b/application/index/model/ShareHandler.php index 876c17b9..9278fa7e 100644 --- a/application/index/model/ShareHandler.php +++ b/application/index/model/ShareHandler.php @@ -57,13 +57,15 @@ class ShareHandler extends Model{ "msg" => "无权操作" ); } + $newPwd = self::getRandomKey(6); Db::name('shares')->where('share_key',$this->shareData["share_key"])->update([ 'type' => $this->shareData["type"] == "public"?"private":"public", - 'share_pwd' => self::getRandomKey(6) + 'share_pwd' => $newPwd ]); return array( "error" =>0, - "msg" => "更改成功" + "msg" => "更改成功", + "newPwd" => $newPwd, ); } @@ -95,6 +97,48 @@ class ShareHandler extends Model{ return $fileObj->getThumb(); } + public function getDocPreview($user,$path,$inFolder){ + $checkStatus = $this->checkSession($user); + if(!$checkStatus[0]){ + return [$checkStatus[0],$checkStatus[1]]; + } + if($inFolder){ + $reqPath = Db::name('folders')->where('position_absolute',$this->shareData["source_name"])->find(); + $fileObj = new FileManage($reqPath["position_absolute"].$path,$this->shareData["owner"]); + }else{ + $reqPath = Db::name('files')->where('id',$this->shareData["source_name"])->find(); + if($reqPath["dir"] == "/"){ + $reqPath["dir"] = $reqPath["dir"].$reqPath["orign_name"]; + }else{ + $reqPath["dir"] = $reqPath["dir"]."/".$reqPath["orign_name"]; + } + $fileObj = new FileManage($reqPath["dir"],$this->shareData["owner"]); + } + $tmpUrl = $fileObj->signTmpUrl(); + return[true,"http://view.officeapps.live.com/op/view.aspx?src=".urlencode($tmpUrl)]; + } + + public function getContent($user,$path=null,$inFolder){ + $checkStatus = $this->checkSession($user); + if(!$checkStatus[0]){ + return [$checkStatus[0],$checkStatus[1]]; + } + if($inFolder){ + $reqPath = Db::name('folders')->where('position_absolute',$this->shareData["source_name"])->find(); + $fileObj = new FileManage($reqPath["position_absolute"].$path,$this->shareData["owner"]); + }else{ + $reqPath = Db::name('files')->where('id',$this->shareData["source_name"])->find(); + if($reqPath["dir"] == "/"){ + $reqPath["dir"] = $reqPath["dir"].$reqPath["orign_name"]; + }else{ + $reqPath["dir"] = $reqPath["dir"]."/".$reqPath["orign_name"]; + } + $fileObj = new FileManage($reqPath["dir"],$this->shareData["owner"]); + } + $fileObj->getContent(); + exit(); + } + public function checkSession($user){ if($this->lockStatus){ return [false,"会话过期,请刷新页面"]; @@ -146,7 +190,7 @@ class ShareHandler extends Model{ } $reqPath = Db::name('folders')->where('position_absolute',$this->shareData["source_name"])->find(); $path = $path == "/"?"":$path; - return FileManage::ListFile($this->shareData["source_name"].$path,$this->shareData["owner"]); + return FileManage::ListFile($this->shareData["source_name"].$path,$this->shareData["owner"],true,$this->shareData["source_name"]); } public function Preview($user){ @@ -235,7 +279,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 +287,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 +301,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 +329,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/model/UploadHandler.php b/application/index/model/UploadHandler.php index e209f80c..b6e2d71d 100644 --- a/application/index/model/UploadHandler.php +++ b/application/index/model/UploadHandler.php @@ -58,7 +58,7 @@ class UploadHandler extends Model{ $this->setError("空间容量不足",false); } FileManage::storageCheckOut($this->userId,$chunkSize); - if($chunkSize >=4195304){ + if($chunkSize >config('upload.chunk_size')){ $this->setError("分片错误",false); } $chunkObj=fopen (ROOT_PATH . 'public/uploads/chunks/'.$this->chunkData["obj_name"].".chunk","w+"); @@ -198,8 +198,8 @@ class UploadHandler extends Model{ if(!$fileObj || !$chunkObj){ $this->setError("文件创建失败",false); } - $content = fread($chunkObj, 4195304); - fwrite($fileObj, $content, 4195304); + $content = fread($chunkObj, config('upload.chunk_size')); + fwrite($fileObj, $content, config('upload.chunk_size')); unset($content); fclose($chunkObj); unlink(ROOT_PATH . 'public/uploads/chunks/'.$value["obj_name"].".chunk"); diff --git a/application/index/model/User.php b/application/index/model/User.php index 0a87ad6f..d6b15af5 100644 --- a/application/index/model/User.php +++ b/application/index/model/User.php @@ -127,6 +127,7 @@ class User extends Model{ 'delay_time' =>0, 'avatar' => "default", 'profile' => true, + 'options' => "{}", ]; if(Db::name('users')->insert($sqlData)){ $userId = Db::name('users')->getLastInsID(); @@ -355,6 +356,13 @@ class User extends Model{ } } + public function changeOption($optionKey,$optionValue){ + $options = json_decode($this->userSQLData["options"],true); + $options[$optionKey] = $optionValue; + Db::name("users")->where("id",$this->uid)->update(["options" => json_encode($options)]); + return [1,1]; + } + public function changePwd($origin,$new){ if(md5(config('salt').$origin) != $this->userSQLData["user_pass"]){ return [0,"原密码错误"]; diff --git a/application/index/view/error.html b/application/index/view/error.html index c7e74ff2..806ca31d 100644 --- a/application/index/view/error.html +++ b/application/index/view/error.html @@ -1,6 +1,4 @@ -{extend name="header_public" /} -{block name="title"}错误提示 - {$options.siteName}{/block} -{block name="content"} + @@ -19,6 +17,4 @@ -{$options.js_code} -{/block} \ No newline at end of file diff --git a/application/index/view/explore/result.html b/application/index/view/explore/result.html index db89f0bc..af9e3261 100644 --- a/application/index/view/explore/result.html +++ b/application/index/view/explore/result.html @@ -1,76 +1,23 @@ -{extend name="header_public" /} -{block name="title"}“{$keyWords}”搜索结果 - {$options.siteName}{/block} -{block name="content"} - - - -