Compare commits

..
11 Commits
Author SHA1 Message Date
HFO4 ddc0b6ad4b release:1.1.1 2018-10-20 17:08:50 +08:00
HFO4 75cbbcaa10 add: Crontab config reminder 2018-10-20 15:37:20 +08:00
HFO4 060f7a2081 feat: Manage page for task queue 2018-10-20 15:25:35 +08:00
HFO4 a67185c750 fix: installation error in command line 2018-10-19 16:31:51 +08:00
HFO4 38b11c1651 Merge branch 'master' of https://github.com/HFO4/Cloudreve 2018-10-19 16:30:41 +08:00
HFO4 96b7f4c97d fix: installation error in command line 2018-10-19 16:30:08 +08:00
AaronLiuandGitHub f600b21faa Merge pull request #95 from samnela/change-psr-autoload
moved to psr-4
2018-09-15 19:41:59 +08:00
AaronLiuandGitHub 1693bf800b Merge pull request #88 from Yuanuo/patch-02
PHP basename 中文乱码问题
2018-09-15 19:36:54 +08:00
Samuel NELA f39334125b moved to psr-4 2018-09-14 23:34:33 +02:00
HFO4 9ee144d870 change: Telegram group invite link 2018-09-13 22:16:49 +08:00
Yuanuo 2807c1c79e PHP basename 中文乱码问题
php basename()无法获取带中文字符的文件名(乱码)
2018-08-04 14:08:59 +08:00
17 changed files with 288 additions and 10 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ Cloudreve - Make the cloud easy for everyone
[![Latest Unstable Version](https://poser.pugx.org/hfo4/cloudreve/v/unstable)](https://packagist.org/packages/hfo4/cloudreve)
[![License](https://poser.pugx.org/hfo4/cloudreve/license)](https://packagist.org/packages/hfo4/cloudreve)
[主页](https://cloudreve.org) | [论坛](https://forum.cloudreve.org) | [演示站](https://pan.aoaoao.me) | [QQ群](https://jq.qq.com/?_wv=1027&k=5TX6sJY) |[Telegram群组](https://github.com/HFO4/Cloudreve)
[主页](https://cloudreve.org) | [论坛](https://forum.cloudreve.org) | [演示站](https://pan.aoaoao.me) | [QQ群](https://jq.qq.com/?_wv=1027&k=5TX6sJY) |[Telegram群组](https://t.me/cloudreve)
基于ThinkPHP构建的网盘系统,能够助您以较低成本快速搭建起公私兼备的网盘。
+1 -1
View File
@@ -18,7 +18,7 @@ return [
// 应用命名空间
'app_namespace' => 'app',
// 应用调试模式
'app_debug' => true,
'app_debug' => false,
// 应用Trace
'app_trace' => false,
// 应用模式状态
+1 -1
View File
@@ -39,7 +39,7 @@ class Task extends Command
$task->taskModel = $newTaskInfo;
$task->input = $input;
$task->output = $output;
$task->Do();
$task->Doit();
if($task->status=="error"){
$output->writeln("[Error] ".$task->errorMsg);
Db::name("task")->where("id",$newTaskInfo["id"])->update(["status"=>"error|".$task->errorMsg]);
+19
View File
@@ -33,9 +33,15 @@ class Admin extends Controller{
$this->redirect(url('/Admin/UpdateDb','',''));
exit();
}
if($this->adminObj->checkCron()){
$isCronOk = true;
}else{
$isCronOk = false;
}
return view('admin_index', [
'options' => $this->siteOptions,
'statics' => $this->adminObj->getStatics(),
'isCronOk' => $isCronOk,
]);
}
@@ -252,6 +258,10 @@ class Admin extends Controller{
return $this->adminObj->saveAria2Setting(input('post.'));
}
public function SaveTaskOption(){
return $this->adminObj->saveTaskOption(input('post.'));
}
public function SendTestMail(){
return $this->adminObj->sendTestMail(input('post.'));
}
@@ -474,6 +484,15 @@ class Admin extends Controller{
]);
}
public function Queue(){
$taskOption = Option::getValue("task_queue_token");
return view('task', [
'options' => $this->siteOptions,
'taskOption' => $taskOption,
'task' => $this->adminObj->getTasks(),
]);
}
public function PurchaseGroup(){
$groupData = json_decode(Option::getValue("group_sell_data"),true);
foreach ($groupData as $key => $value) {
+42
View File
@@ -5,12 +5,16 @@ use think\Controller;
use think\Db;
use think\Request;
use \app\index\model\Task;
use \app\index\model\Option;
class Queue extends Controller{
public function __construct(\think\Request $request = null){
$token = Option::getValue("task_queue_token");
if($token==""){
abort(403);
}
if(Request::instance()->header("Authorization") !="Bearer ".$token){
abort(403);
}
@@ -29,6 +33,8 @@ class Queue extends Controller{
public function getList(){
$size = input("get.num");
$tasks = Db::name("task")->where("status","todo")->limit($size)->select();
$taskID = array_column($tasks,"id");
Db::name("task")->where("id","in",$taskID)->update(["status"=>"processing"]);
if(empty($tasks)){
return "none";
}else{
@@ -36,4 +42,40 @@ class Queue extends Controller{
}
}
public function getPolicy(){
$id = input("get.id");
$policy = Db::name("policy")->where("id",$id)->find();
if(empty(($policy))){
abort(404);
}else{
return json($policy);
}
}
public function setSuccess(){
$id = input("get.id");
$task = new Task($id);
$task->taskModel = Db::name("task")
->where("id",$id)
//->where("status","processing")
->find();
if(empty($task->taskModel)){
return json(["error"=>true,"msg"=>"未找到任务"]);
}
return json($task->setSuccess());
}
public function setError(){
$id = input("get.id");
$task = new Task($id);
$task->taskModel = Db::name("task")
->where("id",$id)
//->where("status","processing")
->find();
if(empty($task->taskModel)){
return json(["error"=>true,"msg"=>"未找到任务"]);
}
return json($task->Error());
}
}
+19
View File
@@ -31,6 +31,14 @@ class AdminHandler extends Model{
return false;
}
public function checkCron(){
$cronRecord = Db::name("corn")->where("name","delete_unseful_chunks")->find();
if($cronRecord["last_excute"]+$cronRecord["interval_s"]+"1800"<time()){
return false;
}
return true;
}
public function getStatics(){
$statics["fileNum"] = Db::name('files')->count();
$statics["privateShareNum"] = Db::name('shares')->where("type","private")->count();
@@ -109,6 +117,10 @@ class AdminHandler extends Model{
return $this->saveOptions($options);
}
public function saveTaskOption($options){
return $this->saveOptions($options);
}
public function saveMailTemplate($options){
return $this->saveOptions($options);
}
@@ -394,6 +406,13 @@ class AdminHandler extends Model{
$this->pageNow = input("?get.page")?input("get.page"):1;
}
public function getTasks(){
$taskData = Db::name("task")
->order("id DESC")
->paginate(10);
return $taskData;
}
public function listFile(){
$pageSize = !cookie('?pageSize') ? 10 : cookie('pageSize');
$orderType = empty(cookie('orderMethodFile')) ? "id DESC" : cookie('orderMethodFile');
+1 -1
View File
@@ -293,7 +293,7 @@ class Aria2 extends Model{
"originPath" => $quenInfo["files"][$sqlData["file_index"]]["path"],
"objname" => $fileName,
"savePath" => $generatePath,
"fsize" => $quenInfo["files"][$sqlData["file_index"]]["length"],
"fsize" => (int)$quenInfo["files"][$sqlData["file_index"]]["length"],
"picInfo" => $picInfo,
"policyId" => $this->policy["id"],
]);
+1 -1
View File
@@ -168,7 +168,7 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota{
$dirName = end($explode);
$rootPath = rtrim($path,"/".$dirName);
$rootPath = empty($rootPath) ? "/" : $rootPath;
$dirData = Db::name('folders')->where('owner',$this->uid)->where('position',dirname($path) == "\\" ?"/":dirname($path))->where("folder_name",basename($path))->find();
$dirData = Db::name('folders')->where('owner',$this->uid)->where('position',dirname($path) == "\\" ?"/":dirname($path))->where("folder_name",getDirName($path))->find();
if(empty($dirData)){
return false;
}
+58 -1
View File
@@ -53,7 +53,7 @@ class Task extends Model{
*
* @return void
*/
public function Do(){
public function Doit(){
switch ($this->taskModel["type"]){
case "uploadSingleToOnedrive":
$this->uploadSingleToOnedrive();
@@ -350,6 +350,63 @@ class Task extends Model{
FileManage::storageGiveBack($this->taskModel["uid"],$this->taskContent["fsize"]);
}
public function setSuccess(){
$this->taskContent = json_decode($this->taskModel["attr"],true);
$policyData = Db::name("policy")->where("id",$this->taskContent["policyId"])->find();
$this->policyModel = $policyData;
$onedrive = new Client([
'stream_back_end' => \Krizalys\Onedrive\StreamBackEnd::TEMP,
'client_id' => $policyData["bucketname"],
// Restore the previous state while instantiating this client to proceed in
// obtaining an access token.
'state' => json_decode($policyData["sk"]),
]);
$jsonData = array(
"path" => $this->taskContent["path"],
"fname" => $this->taskContent["fname"],
"objname" => $this->taskContent["savePath"]."/".$this->taskContent["objname"],
"fsize" => $this->taskContent["fsize"],
);
$addAction = FileManage::addFile($jsonData,$policyData,$this->taskModel["uid"],$this->taskContent["picInfo"]);
if(!$addAction[0]){
$this->setError($addAction[1],true,"/me/drive/root:/".$this->taskContent["savePath"]."/".rawurlencode($this->taskContent["objname"]),$onedrive);
$this->cleanTmpFile();
Db::name("task")->where("id",$this->taskModel["id"])->update(["status"=>"error|".$this->errorMsg]);
return ["error"=>true,"msg"=>$this->errorMsg];
}
$this->cleanTmpFile();
if($this->taskModel["type"] == "UploadLargeRemoteDownloadFileToOnedrive" || $this->taskModel["type"] == "uploadChunksToOnedrive"){
$this->cleanTmpChunk();
}
Db::name("task")->where("id",$this->taskModel["id"])->update(["status"=>"complete"]);
return ["error"=>false,"msg"=>null];
}
public function Error(){
$this->taskContent = json_decode($this->taskModel["attr"],true);
$policyData = Db::name("policy")->where("id",$this->taskContent["policyId"])->find();
$this->policyModel = $policyData;
$onedrive = new Client([
'stream_back_end' => \Krizalys\Onedrive\StreamBackEnd::TEMP,
'client_id' => $policyData["bucketname"],
// Restore the previous state while instantiating this client to proceed in
// obtaining an access token.
'state' => json_decode($policyData["sk"]),
]);
$this->setError("",false,"/me/drive/root:/".$this->taskContent["savePath"]."/".rawurlencode($this->taskContent["objname"]),$onedrive);
$this->cleanTmpFile();
if($this->taskModel["type"] == "UploadLargeRemoteDownloadFileToOnedrive" || $this->taskModel["type"] == "uploadChunksToOnedrive"){
$this->cleanTmpChunk();
}
Db::name("task")->where("id",$this->taskModel["id"])->update(["status"=>"error"]);
}
}
?>
@@ -11,7 +11,14 @@
<li class="breadcrumb-item active">数据概况</li>
</ol>
<!-- Icon Cards-->
{eq name="isCronOk" value="true"}
{else/}
<div class="alert alert-danger" role="alert">
<strong>警告!Cron定时任务疑似未执行</strong><p>检测到<a href="/Admin/Cron">定时任务</a>未正常执行,请检查您的定时任务配置。您可以通过Crontab或者其他网站监控服务,让 “您的域名/Cron” 此地址每隔一段时间被访问一次。</p>
</div>
{/eq}
<div class="row">
<div class="col-xl-3 col-sm-6 mb-3">
<div class="card text-white bg-primary o-hidden h-100">
<div class="card-body">
+99
View File
@@ -0,0 +1,99 @@
{extend name="header_admin" /}
{block name="title"}任务队列 - {$options.siteName}{/block}
{block name="content"}
<div class="content-wrapper">
<div class="container-fluid">
<!-- Breadcrumbs-->
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="/Admin">管理面板</a>
</li>
<li class="breadcrumb-item active">任务队列</li>
<li class="breadcrumb-item active">配置</li>
</ol>
<!-- Area Chart Example-->
<div class="row">
<div class="col-12">
<h2>任务队列</h2>
<br>
<div class="card">
<div class="card-header">
<ul class="nav nav-tabs card-header-tabs">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#options"><i class="fa fa-cog" aria-hidden="true"></i> 配置</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#list"><i class="fa fa-list" aria-hidden="true"></i> 任务列表</a>
</li>
</ul>
</div>
<div class="card-body">
<div class="tab-content" >
<div class="tab-pane fade show active" id="options" role="tabpanel" aria-labelledby="pills-home-tab">
<form id="taskOptions">
<div class="row form-setting">
<div class="col-md-1 form-label ">
<label for="fromName" class="col-form-label col-form-label-sm">Token</label>
</div>
<div class="col-md-4">
<input type="text" class="form-control" name="task_queue_token" id="task_queue_token" value="{$taskOption}" spellcheck="false">
</div>
<div class="col-md-4 option-des"> 任务队列鉴权Token,应该与任务队列配置文件conf.yaml中的token保持一致,留空表示禁止任务队列请求</div>
</div>
<div class="row form-setting">
<div class="col-md-1 form-label ">
</div>
<div class="col-md-4"> <button type="button" class="btn btn-outline-secondary" id="generateToken">随机生成Token</button> <button type="button" class="btn btn-primary" id="saveTask">保存设置</button></div>
<div class="col-md-4 option-des"> </div>
<br><br><br>
</div>
</form>
</div>
<div class="tab-pane fade" id="list" role="tabpanel" aria-labelledby="pills-profile-tab">
<table class="table">
<thead>
<tr>
<th scope="col" class="textCenter">#</th>
<th scope="col" width="50%">任务名</th>
<th scope="col" class="textCenter">状态</th>
<th scope="col" class="textCenter">创建日期</th>
<th scope="col" class="textCenter">创建者UID</th>
</tr>
</thead>
<tbody id="listContent">
{volist name='task' id='t'}
<tr id="i-{$t.id}" >
<th scope="row" class="textCenter">{$t.id}</th>
<td>{$t.task_name}</td>
<td class="textCenter">{$t.status}</td>
<td class="textCenter">{$t.addtime}</td>
<td class="textCenter">{$t.uid}</td>
</tr>
{/volist}
</tbody>
</table>
{$task->render()}
</div>
<div class="tab-pane fade" id="tools" role="tabpanel" aria-labelledby="pills-profile-tab">
ddd
</div>
</div>
</div>
</div><br>
</div>
</div>
<!-- Example DataTables Card-->
</div>
<!-- /.container-fluid-->
</div>
{/block}
{block name="js"}
<script src="/static/js/admin/summernote.min.js"></script>
<script src="/static/js/admin/summernote-zh-CN.min.js"></script>
<script src="/static/js/admin/task.js"></script>
{/block}
+3
View File
@@ -122,6 +122,9 @@
<span class="nav-link-text">其他</span>
</a>
<ul class="sidenav-second-level collapse" id="else">
<li>
<a href="/Admin/Queue">任务队列</a>
</li>
<li>
<a href="/Admin/Cron">定时任务</a>
</li>
+1 -1
View File
@@ -1 +1 @@
{"type":"","version":"1.1.0","version_id":5,"db_version":3}
{"type":"","version":"1.1.1","version_id":6,"db_version":4}
+1 -1
View File
@@ -4,7 +4,7 @@
"keywords": ["php", "cloud", "ThinkPHP", "file-sharing"],
"homepage": "https://cloudreve.org",
"type": "project",
"license": "GPL-3.0-only",
"license": "GPL-3.0-only",
"authors": [
{
"name": "Aaron",
+2 -2
View File
@@ -73,7 +73,7 @@ INSERT INTO `sd_corn` (`id`, `rank`, `name`, `des`, `last_excute`, `interval_s`,
(1, 2, 'delete_unseful_chunks', '删除分片上传产生的失效文件块', 0, 3600, 1),
(2, 1, 'delete_callback_data', '删除callback记录', 0, 86400, 1),
(3, 1, 'flush_aria2', '刷新离线下载状态', 0, 30, 1),
(4, 3, 'flush_onedrive_token', '刷新Onedrive Token', 1536821807, 3000, 1);
(4, 3, 'flush_onedrive_token', '刷新Onedrive Token', 0, 3000, 1);
-- --------------------------------------------------------
--
@@ -201,7 +201,7 @@ INSERT INTO `sd_options` (`id`, `option_name`, `option_value`, `option_type`) VA
(53, 'aria2_token', 'your token', 'aria2'),
(54, 'aria2_rpcurl', 'http://127.0.0.1:6800/', 'aria2'),
(55, 'aria2_options', '{\"max-tries\":5}', 'aria2'),
(NULL, 'task_queue_token', '', 'task');
(56, 'task_queue_token', '', 'task');
-- --------------------------------------------------------
--
Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

+32
View File
@@ -0,0 +1,32 @@
$("#saveTask").click(function() {
$("#saveTask").attr("disabled", "true");
$.post("/Admin/SaveTaskOption",
$("#taskOptions").serialize()
, function(data) {
if (data.error == "1") {
toastr["warning"](data.msg);
$("#saveTask").removeAttr("disabled");
} else if (data.error == "200") {
toastr["success"]("设置已保存");
$("#saveTask").removeAttr("disabled");
}else{
toastr["warning"]("未知错误");
$("#saveTask").removeAttr("disabled");
}
});
})
$("#generateToken").click(function(){
len = 64;
  var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
var maxPos = $chars.length;
  var pwd = '';
  for (i = 0; i < len; i++) {
    pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  }
  $("#task_queue_token").val(pwd);
})
$(document).ready(function(){
if(document.location.href.indexOf("page")!=-1){
$("[href='#list']").click();
}
})