add list for completed remote download and fix storage check before starting downloading

This commit is contained in:
HFO4 2018-04-18 20:31:24 +08:00
parent 3326c9232e
commit 412541a540
5 changed files with 207 additions and 58 deletions

View file

@ -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);
}
}

View file

@ -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;

View file

@ -1,60 +1,83 @@
{extend name="header_home" /}
{block name="title"}离线下载管理- {$options.siteName}{/block}
{block name="content"}
<script src="/static/js/remoteDownload.js"></script>
<style type="text/css">
.col-md-3{
padding-right: 15px;
padding-left: 15px;
}
</style>
</head>
<body >
<div id="container">
{include file="navbar_home" /}
<script src="/static/js/remoteDownload.js"></script>
<style type="text/css">
.col-md-3{
padding-right: 15px;
padding-left: 15px;
}
</style>
</head>
<body >
<div id="container">
{include file="navbar_home" /}
<div class="col-md-10 quota_content">
<h1>离线下载管理</h1>
<br>
<div class="fix_side">
<div class="col-md-10 quota_content">
<h1>离线下载管理</h1>
<br>
<div class="fix_side">
<div class="fix">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">正在进行中</div>
<div class="panel-body centerTable" id="loadStatus">
更新状态数据中...
</div>
<div class="table-responsive" style="display: none">
<table class="table">
<thead>
<tr>
<th width="5%" class="centerTable">#</th>
<th width="50%" >文件名</th>
<th class="centerTable">大小</th>
<th class="centerTable">储存位置</th>
<th class="centerTable">下载速度</th>
<th class="centerTable">进度</th>
<th class="centerTable">操作</th>
</tr>
</thead>
<tbody id="itemContent">
</tbody>
</table>
</div>
<div class="fix">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">正在进行中 <i class="fa fa-refresh" aria-hidden="true" title="刷新数据" onclick="refresh()"></i></div>
<div class="panel-body centerTable" id="loadStatus">
更新状态数据中...
</div>
<div class="table-responsive" style="display: none">
<table class="table">
<thead>
<tr>
<th width="5%" class="centerTable">#</th>
<th width="50%" >文件名</th>
<th class="centerTable">大小</th>
<th class="centerTable">储存位置</th>
<th class="centerTable">下载速度</th>
<th class="centerTable">进度</th>
<th class="centerTable">操作</th>
</tr>
</thead>
<tbody id="itemContent">
</tbody>
</table>
</div>
</div>
</div>
<br>
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading">已完成 </i></div>
<div class="table-responsive" >
<table class="table">
<thead>
<tr>
<th width="5%" class="centerTable">#</th>
<th width="50%" >文件名</th>
<th class="centerTable">大小</th>
<th class="centerTable">储存位置</th>
<th class="centerTable">状态</th>
<th class="centerTable">操作</th>
</tr>
</thead>
<tbody id="completeItemContent">
</tbody>
</table>
</div>
<div class="panel-body centerTable" id="loadButton">
<button class="btn btn-primary" id="loadFinished">点击加载已完成列表</button>
</div>
</div>
</body>
<script src="/static/js/material.js"></script>
<script type="text/javascript">
upload_load=0;
</script>
{$options.js_code}
</html>
{/block}
</div>
</div>
<br>
</div>
</body>
<script src="/static/js/material.js"></script>
<script type="text/javascript">
upload_load=0;
</script>
{$options.js_code}
</html>
{/block}

View file

@ -6,4 +6,18 @@ body{background-color:#EEE}body.inverse{background:#333}body.inverse,body.invers
.tr-bar {
background-image: -webkit-gradient(linear, left top, right top, from(#ecefff), to(white), color-stop(0.5, #ecefff), color-stop(0.5, white));
background-image: -moz-linear-gradient(0, #ecefff 0%, #ecefff 50%, white 50%, white 100%);
}
.download-error{
color: #F44336;
font-weight: 700;
}
.td-error{
background-color:#ffebea;
}
.download-success{
color:#009688;
font-weight: 700;
}
.td-success{
background-color:#edffee;
}

View file

@ -1,17 +1,83 @@
function getMemory() {
$.get("/Member/Memory", function(data) {
var dataObj = eval("(" + data + ")");
if (dataObj.rate >= 100) {
$("#memory_bar").css("width", "100%");
$("#memory_bar").addClass("progress-bar-warning");
toastr["error"]("您的已用容量已超过容量配额,请尽快删除多余文件或购买容量");
} else {
$("#memory_bar").css("width", dataObj.rate + "%");
}
$("#used").html(dataObj.used);
$("#total").html(dataObj.total);
});
}
page = 1;
window.onload = function() {
$.material.init();
getMemory();
}
$(function() {
$("#loadFinished").click(function(){
$.getJSON("/RemoteDownload/ListFinished?page="+page, function(data) {
if(data.length == 0){
$("#loadFinished").html("已加载全部");
$("#loadFinished").attr("disabled","true");
}else{
$("#loadFinished").html("继续加载");
}
data.forEach(function(e) {
$("#completeItemContent").append(function() {
var row = '<tr id="i-' + e["id"] + '" data-pid="'+e["pid"]+'"><th scope="row" class="centerTable">' + e["id"] + '</th><td>' + e["fileName"] + '</td>';
row = row + '<td class="centerTable">' + bytesToSize(e["totalLength"]) + '</td>';
row = row + '<td class="centerTable">' + e["save_dir"] + '</td>';
switch(e["status"]){
case "error":
row = row +'<td class="centerTable"><span class="download-error" data-toggle="tooltip" data-placement="top" title="'+e["msg"]+'">失败</span></td>'
break;
case "canceled":
row = row +'<td class="centerTable"><span >取消</span></td>'
break;
case "canceled":
row = row +'<td class="centerTable"><span >取消</span></td>'
break;
case "complete":
row = row +'<td class="centerTable"><span class="download-success">完成</span></td>'
break;
}
row = row + '<td class="centerTable"><a href="javascript:" onclick="delete('+e["id"]+')" >删除记录</a></td>'
return row + "</tr>";
});
switch(e["status"]){
case "error":
$("#i-" + e["id"]).addClass("td-error");
$('[data-toggle="tooltip"]').tooltip()
break;
case "complete":
$("#i-" + e["id"]).addClass("td-success");
break;
}
});
page++;
})
})
})
$.get("/RemoteDownload/FlushUser", function() {
$("#loadStatus").html("加载下载列表中...");
loadDownloadingList();
})
function loadDownloadingList() {
$("#itemContent").html("");
$.getJSON("/RemoteDownload/ListDownloading", function(data) {
$("#itemContent").html();
if(data.length == 0){
$("#loadStatus").html("下载列表为空");
}
data.forEach(function(e) {
$("#itemContent").append(function() {
var row = '<tr id="i-' + e["id"] + '"><th scope="row" class="centerTable">' + e["id"] + '</th><td>' + e["fileName"] + '</td>';
var row = '<tr id="i-' + e["id"] + '" data-pid="'+e["pid"]+'"><th scope="row" class="centerTable">' + e["id"] + '</th><td>' + e["fileName"] + '</td>';
row = row + '<td class="centerTable">' + bytesToSize(e["totalLength"]) + '</td>';
row = row + '<td class="centerTable">' + e["save_dir"] + '</td>';
if (e["downloadSpeed"] == "0") {
@ -57,7 +123,17 @@ function loadDownloadingList() {
if(data.error){
toastr["warning"](data.message);
}else{
var pid = $("#i-"+id).attr("data-pid");
$("[data-pid='"+pid+"'").remove();
toastr["success"](data.message);
}
})
}
function refresh(){
$.get("/RemoteDownload/FlushUser?i="+Math.random(), function() {
$("#loadStatus").html("加载下载列表中...");
loadDownloadingList();
})
}