diff --git a/application/index/controller/Home.php b/application/index/controller/Home.php index 5f9f78c8..f73650c0 100644 --- a/application/index/controller/Home.php +++ b/application/index/controller/Home.php @@ -38,6 +38,16 @@ class Home extends Controller{ ]); } + public function Download(){ + $userInfo = $this->userObj->getInfo(); + $groupData = $this->userObj->getGroupData(); + return view('download', [ + 'options' => Option::getValues(['basic','group_sell']), + 'userInfo' => $userInfo, + 'groupData' => $groupData, + ]); + } + public function Album(){ $userInfo = $this->userObj->getInfo(); $list = Db::name("files")->where("upload_user",$this->userObj->uid) @@ -60,7 +70,7 @@ class Home extends Controller{ $listData = $list->all(); $pageNow = input("?get.page")?input("get.page"):1; if($pageNow>$pageCount){ - $this->error('页面不存在',404,Option::getValues(['basic','group_sell'])); + $this->error('您当前没有上传任何图片',404,Option::getValues(['basic','group_sell'])); } return view('album', [ 'options' => Option::getValues(['basic','group_sell']), diff --git a/application/index/controller/RemoteDownload.php b/application/index/controller/RemoteDownload.php index 98225cac..1411b651 100644 --- a/application/index/controller/RemoteDownload.php +++ b/application/index/controller/RemoteDownload.php @@ -29,12 +29,12 @@ class RemoteDownload extends Controller{ return true; } - private function insertRecord($aria2,$url){ + private function insertRecord($aria2,$url,$path){ Db::name("download")->insert([ "pid" => $aria2->pid, "path_id" => $aria2->pathId, "owner" => $this->userObj->uid, - "save_dir" => 1, + "save_dir" => $path, "status" => "ready", "msg" => "", "info"=>"", @@ -53,7 +53,7 @@ class RemoteDownload extends Controller{ $aria2 = new Aria2($aria2Options); $downloadStart = $aria2->addUrl(input("post.url")); if($aria2->reqStatus){ - $this->insertRecord($aria2,input("post.url")); + $this->insertRecord($aria2,input("post.url"),input("post.path")); return json(["result"=>['success'=>true,'error'=>null]]); }else{ return json(["result"=>['success'=>false,'error'=>$aria2->reqMsg]]); @@ -67,12 +67,13 @@ class RemoteDownload extends Controller{ } $aria2Options = Option::getValues(["aria2"]); $aria2 = new Aria2($aria2Options); - $torrentObj = new \app\index\model\FileManage(input("post.path"),$this->userObj->uid); + $torrentObj = new \app\index\model\FileManage(input("post.id"),$this->userObj->uid,true); $downloadStart = $aria2->addTorrent($torrentObj->signTmpUrl()); if($aria2->reqStatus){ - $this->insertRecord($aria2,input("post.path")); + $this->insertRecord($aria2,input("post.id"),input("post.savePath")); + return json(["result"=>['success'=>true,'error'=>null]]); }else{ - return json(['error'=>1,'message'=>$aria2->reqMsg]); + return json(["result"=>['success'=>false,'error'=>$aria2->reqMsg]]); } } @@ -88,4 +89,21 @@ class RemoteDownload extends Controller{ } } + public function FlushUser(){ + $aria2Options = Option::getValues(["aria2"]); + $aria2 = new Aria2($aria2Options); + $toBeFlushed = Db::name("download") + ->where("owner",$this->userObj->uid) + ->where("status","<>","complete") + ->where("status","<>","error") + ->select(); + foreach ($toBeFlushed as $key => $value) { + $aria2->flushStatus($value["id"],$this->userObj->uid,$this->userObj->getPolicy()); + } + } + + public function ListDownloading(){ + return json(["s"=>"s"]); + } + } \ No newline at end of file diff --git a/application/index/model/Aria2.php b/application/index/model/Aria2.php index 508bc919..dac3d7a4 100644 --- a/application/index/model/Aria2.php +++ b/application/index/model/Aria2.php @@ -157,7 +157,7 @@ class Aria2 extends Model{ "pid" => $sqlData["pid"], "path_id" => $sqlData["path_id"], "owner" => $sqlData["owner"], - "save_dir" => 1, + "save_dir" => $sqlData["save_dir"], "status" => "ready", "msg" => "", "info"=>"", @@ -198,7 +198,7 @@ class Aria2 extends Model{ rename($quenInfo["files"][$sqlData["file_index"]]["path"],$savePath); @unlink(dirname($quenInfo["files"][$sqlData["file_index"]]["path"])); $jsonData = array( - "path" => "", + "path" => ltrim(str_replace("/", ",", $sqlData["save_dir"]),","), "fname" => basename($quenInfo["files"][$sqlData["file_index"]]["path"]), "objname" => $generatePath.DS.$fileName, "fsize" => $quenInfo["files"][$sqlData["file_index"]]["length"], diff --git a/application/index/model/FileManage.php b/application/index/model/FileManage.php index ba639c38..9bd26255 100644 --- a/application/index/model/FileManage.php +++ b/application/index/model/FileManage.php @@ -22,12 +22,17 @@ class FileManage extends Model{ public $policyData; public $deleteStatus = true; - public function __construct($path,$uid){ - $this->filePath = $path; - $fileInfo = $this->getFileName($path); - $fileName = $fileInfo[0]; - $path = $fileInfo[1]; - $fileRecord = Db::name('files')->where('upload_user',$uid)->where('orign_name',$fileName)->where('dir',$path)->find(); + public function __construct($path,$uid,$byId=false){ + if($byId){ + $fileRecord = Db::name('files')->where('id',$path)->find(); + $this->filePath = rtrim($fileRecord["dir"],"/")."/".$fileRecord["orign_name"]; + }else{ + $this->filePath = $path; + $fileInfo = $this->getFileName($path); + $fileName = $fileInfo[0]; + $path = $fileInfo[1]; + $fileRecord = Db::name('files')->where('upload_user',$uid)->where('orign_name',$fileName)->where('dir',$path)->find(); + } if (empty($fileRecord)){ die('{ "result": { "success": false, "error": "文件不存在" } }'); } diff --git a/application/index/view/home/Download.html b/application/index/view/home/Download.html new file mode 100644 index 00000000..a24692bc --- /dev/null +++ b/application/index/view/home/Download.html @@ -0,0 +1,79 @@ +{extend name="header_home" /} +{block name="title"}离线下载管理- {$options.siteName}{/block} +{block name="content"} + + + +
+