From b2d5547199f83361e60fd4aa8c17f00870411d05 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Thu, 14 Mar 2019 19:03:35 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=B8=80=E4=BA=9B=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E7=A6=BB=E7=BA=BF=E4=B8=8B=E8=BD=BD=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=90=8E=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/Explore.php | 28 ++-- application/index/controller/Home.php | 2 +- application/index/model/Aria2.php | 12 +- application/index/model/CronHandler.php | 51 ++++++ application/index/view/explore/result.html | 139 ++++++++-------- application/index/view/explore/search.html | 47 ------ application/index/view/home/download.html | 152 +++++++++--------- application/index/view/home/download_old.html | 81 ++++++++++ application/index/view/home/home.html | 4 +- application/index/view/member/setting.html | 5 +- application/index/view/share/share_home.html | 2 +- .../index/view/share/share_homr_old.html | 98 ----------- application/route.php | 2 +- mysql.sql | 3 +- 14 files changed, 304 insertions(+), 322 deletions(-) delete mode 100644 application/index/view/explore/search.html create mode 100644 application/index/view/home/download_old.html delete mode 100644 application/index/view/share/share_homr_old.html 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/Home.php b/application/index/controller/Home.php index acff3421..f72eb3d4 100644 --- a/application/index/controller/Home.php +++ b/application/index/controller/Home.php @@ -43,7 +43,7 @@ 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, ]); 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/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/view/explore/result.html b/application/index/view/explore/result.html index db89f0bc..6dfcf7e7 100644 --- a/application/index/view/explore/result.html +++ b/application/index/view/explore/result.html @@ -1,76 +1,75 @@ -{extend name="header_public" /} -{block name="title"}“{$keyWords}”搜索结果 - {$options.siteName}{/block} -{block name="content"} - + + + +
+ + + + + + + +