diff --git a/application/index/controller/Queue.php b/application/index/controller/Queue.php index 84796827..14720991 100644 --- a/application/index/controller/Queue.php +++ b/application/index/controller/Queue.php @@ -5,6 +5,7 @@ use think\Controller; use think\Db; use think\Request; +use \app\index\model\Task; use \app\index\model\Option; class Queue extends Controller{ @@ -29,6 +30,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 +39,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()); + } + } diff --git a/application/index/model/Aria2.php b/application/index/model/Aria2.php index 0f007ae6..ddc556cd 100644 --- a/application/index/model/Aria2.php +++ b/application/index/model/Aria2.php @@ -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"], ]); diff --git a/application/index/model/Task.php b/application/index/model/Task.php index 7c0ffe9e..0cd555aa 100644 --- a/application/index/model/Task.php +++ b/application/index/model/Task.php @@ -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"]); + } + } ?> \ No newline at end of file diff --git a/mysql.sql b/mysql.sql index 423c22ca..9cf08f97 100644 --- a/mysql.sql +++ b/mysql.sql @@ -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'); -- -------------------------------------------------------- -- diff --git a/static/img/sign.png b/static/img/sign.png deleted file mode 100644 index 24fdc66a..00000000 Binary files a/static/img/sign.png and /dev/null differ