add torrent download support

pull/64/head
HFO4 8 years ago
parent ccbb6c7778
commit 6d9b67ac20

@ -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']),

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

@ -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"],

@ -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": "文件不存在" } }');
}

@ -0,0 +1,79 @@
{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" /}
<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>
</tr>
</thead>
<tbody>
<tr class="tr-bar">
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td> <td>the Bird</td>
<td>@twitter</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td> <td>the Bird</td>
<td>@twitter</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td> <td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
</div>
</div>
</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}

@ -129,6 +129,11 @@
<a href="/Home/Album" class="list-group-item">
<i class="fa fa-picture-o" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp; 图片集
</a>
{eq name=':(explode(",",$groupData.aria2)[0] OR explode(",",$groupData.aria2)[1])' value="1"}
<a href="/Home/Download" class="list-group-item">
<i class="fa fa-cloud-download" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp; 离线下载
</a>
{/eq}
</div>
<div clss="usage" style=" visibility: visible;
position: absolute;

File diff suppressed because one or more lines are too long

@ -787,6 +787,7 @@ function(e) {
permissionsUrl: "bridges/php/handler.php",
sourceUrl:"/File/gerSource",
remoteDownloadUrl: "/RemoteDownload/addUrl",
torrentDownloadUrl: "/RemoteDownload/AddTorrent",
basePath: "/",
searchForm: !0,
sidebar: !0,
@ -1051,7 +1052,7 @@ function(e, r) {
s = n.defer(),
l = {
action: "torrentDownload",
path: path,
savePath: path,
id:fileId
};
return o.inprocess = !0,

@ -0,0 +1,9 @@
$.get("/RemoteDownload/FlushUser", function(){
$("#loadStatus").html("加载下载列表中");
loadDownloadingList();
})
function loadDownloadingList(){
$.getJSON("/RemoteDownload/ListDownloading", function(data){
console.log(data);
})
}
Loading…
Cancel
Save