From 412541a5402b66f9e9bff3d469b1ade5c690af1a Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Wed, 18 Apr 2018 20:31:24 +0800 Subject: [PATCH] add list for completed remote download and fix storage check before starting downloading --- .../index/controller/RemoteDownload.php | 34 +++++ application/index/model/Aria2.php | 8 +- application/index/view/home/Download.html | 127 +++++++++++------- static/css/material.css | 14 ++ static/js/remoteDownload.js | 82 ++++++++++- 5 files changed, 207 insertions(+), 58 deletions(-) diff --git a/application/index/controller/RemoteDownload.php b/application/index/controller/RemoteDownload.php index b9076321..d09d0f77 100644 --- a/application/index/controller/RemoteDownload.php +++ b/application/index/controller/RemoteDownload.php @@ -41,6 +41,7 @@ class RemoteDownload extends Controller{ "source" =>$url, "file_index" => 0, "is_single" => 1, + "total_size" => 0, ]); } @@ -65,6 +66,15 @@ class RemoteDownload extends Controller{ if(!$this->checkPerimission(0) || $policyData["policy_type"] != "local"){ return json(['error'=>1,'message'=>'您当前的无用户无法执行此操作']); } + $downloadingLength = Db::name("download") + ->where("owner",$this->userObj->uid) + ->where("status","<>","complete") + ->where("status","<>","error") + ->where("status","<>","canceled") + ->sum("total_size"); + if(!\app\index\model\FileManage::sotrageCheck($this->userObj->uid,$downloadingLength)){ + return json(["result"=>['success'=>false,'error'=>"容量不足"]]); + } $aria2Options = Option::getValues(["aria2"]); $aria2 = new Aria2($aria2Options); $torrentObj = new \app\index\model\FileManage(input("post.id"),$this->userObj->uid,true); @@ -141,5 +151,29 @@ class RemoteDownload extends Controller{ return json($downloadItems); } + public function ListFinished(){ + $page = input("get.page"); + $downloadItems = Db::name("download")->where("owner",$this->userObj->uid)->where("status","not in",["active","ready"])->order('id desc')->page($page.',10')->select(); + foreach ($downloadItems as $key => $value) { + $connectInfo = json_decode($value["info"],true); + if(isset($connectInfo["dir"])){ + $downloadItems[$key]["fileName"] = basename($connectInfo["dir"]); + $downloadItems[$key]["completedLength"] = $connectInfo["completedLength"]; + $downloadItems[$key]["totalLength"] = $connectInfo["totalLength"]; + $downloadItems[$key]["downloadSpeed"] = $connectInfo["downloadSpeed"]; + }else{ + if(floor($value["source"])==$value["source"]){ + $downloadItems[$key]["fileName"] = Db::name("files")->where("id",$value["source"])->column("orign_name"); + }else{ + $downloadItems[$key]["fileName"] = $value["source"]; + } + $downloadItems[$key]["completedLength"] = 0; + $downloadItems[$key]["totalLength"] = 0; + $downloadItems[$key]["downloadSpeed"] = 0; + } + } + return json($downloadItems); + } + } \ No newline at end of file diff --git a/application/index/model/Aria2.php b/application/index/model/Aria2.php index 4798a612..4fa1745b 100644 --- a/application/index/model/Aria2.php +++ b/application/index/model/Aria2.php @@ -119,6 +119,7 @@ class Aria2 extends Model{ "errorMessage" => isset($respondData["result"]["errorMessage"]) ? $respondData["result"]["errorMessage"] : "", ]), "msg" => isset($respondData["result"]["errorMessage"]) ? $respondData["result"]["errorMessage"] : "", + "total_size" => $respondData["result"]["files"][$downloadInfo["file_index"]]["length"], ]); switch ($respondData["result"]["status"]) { case 'complete': @@ -191,6 +192,7 @@ class Aria2 extends Model{ "source" =>$sqlData["source"], "file_index" => $key, "is_single" => 0, + "total_size" => 0, ]); } Db::name("download")->where("id",$sqlData["id"])->delete(); @@ -239,7 +241,7 @@ class Aria2 extends Model{ $this->setError($quenInfo,$sqlData,$addAction[1]); return false; } - FileManage::storageCheckOut($this->uid,(int)$quenInfo["files"][$sqlData["file_index"]]["length"]); + FileManage::storageCheckOut($this->uid,$quenInfo["files"][$sqlData["file_index"]]["length"]); } private function setError($quenInfo,$sqlData,$msg,$status="error",$delete=true){ @@ -303,10 +305,10 @@ class Aria2 extends Model{ } private function storageCheck($quenInfo,$sqlData){ - if(!FileManage::sotrageCheck($this->uid,(int)$quenInfo["totalLength"])){ + if(!FileManage::sotrageCheck($this->uid,$quenInfo["totalLength"])){ return false; } - if(!FileManage::sotrageCheck($this->uid,(int)$quenInfo["completedLength"])){ + if(!FileManage::sotrageCheck($this->uid,$quenInfo["completedLength"])){ return false; } return true; diff --git a/application/index/view/home/Download.html b/application/index/view/home/Download.html index 1bcdd4b3..02d58c0d 100644 --- a/application/index/view/home/Download.html +++ b/application/index/view/home/Download.html @@ -1,60 +1,83 @@ {extend name="header_home" /} {block name="title"}离线下载管理- {$options.siteName}{/block} {block name="content"} - - - -
-# | +文件名 | +大小 | +储存位置 | +状态 | +操作 | +
---|