mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-15 05:12:49 +00:00
feat: 新增压缩下载完成后系统机器人提醒
This commit is contained in:
parent
e4070e249d
commit
faf5dec08a
@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
||||
use App\Models\WebSocketDialogMsg;
|
||||
use App\Models\WebSocketDialog;
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Models\AbstractModel;
|
||||
use App\Tasks\FilePackTask;
|
||||
use App\Models\File;
|
||||
use App\Models\FileContent;
|
||||
use App\Models\FileLink;
|
||||
@ -1020,15 +1020,15 @@ class FileController extends AbstractController
|
||||
}
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
$zipName = 'temp/download/' . date("Ym") . '/' . $user->userid . '/' . $downName;
|
||||
$zipPath = storage_path('app/'.$zipName);
|
||||
$zipName = 'tmp/file/' . date("Ym") . '/' . $user->userid . '/' . $downName;
|
||||
$zipPath = public_path($zipName);
|
||||
Base::makeDir(dirname($zipPath));
|
||||
|
||||
if ($zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) {
|
||||
return Base::retError('创建压缩文件失败');
|
||||
}
|
||||
|
||||
go(function() use ($zip, $files, $downName) {
|
||||
go(function() use ($user, $zip, $files, $downName, $zipName) {
|
||||
Coroutine::sleep(0.1);
|
||||
// 压缩进度
|
||||
$progress = 0;
|
||||
@ -1051,6 +1051,19 @@ class FileController extends AbstractController
|
||||
'progress' => 100
|
||||
]);
|
||||
}
|
||||
//
|
||||
$botUser = User::botGetOrCreate('system-msg');
|
||||
if (empty($botUser)) {
|
||||
return;
|
||||
}
|
||||
if ($dialog = WebSocketDialog::checkUserDialog($botUser, $user->userid)) {
|
||||
$text = "<b>文件下载打包已完成。</b>";
|
||||
$text .= "\n\n";
|
||||
$text .= "文件名:{$downName}";
|
||||
$text .= "\n";
|
||||
$text .= "下载地址:".Base::fillUrl($zipName);
|
||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $text], $botUser->userid, false, false, true);
|
||||
}
|
||||
});
|
||||
|
||||
return Base::retSuccess('success');
|
||||
@ -1074,8 +1087,8 @@ class FileController extends AbstractController
|
||||
{
|
||||
$user = User::auth();
|
||||
$downName = Request::input('name');
|
||||
$zipName = 'temp/download/' . date("Ym") . '/' . $user->userid . '/' . $downName;
|
||||
$zipPath = storage_path('app/'.$zipName);
|
||||
$zipName = 'tmp/file/' . date("Ym") . '/' . $user->userid . '/' . $downName;
|
||||
$zipPath = public_path($zipName);
|
||||
if (!file_exists($zipPath)) {
|
||||
abort(403, "The file does not exist.");
|
||||
}
|
||||
|
||||
@ -102,7 +102,7 @@ class DeleteTmpTask extends AbstractTask
|
||||
*/
|
||||
case 'file_pack':
|
||||
{
|
||||
$path = storage_path('app/temp/download/');
|
||||
$path = public_path('tmp/file/');
|
||||
$dirIterator = new \RecursiveDirectoryIterator($path);
|
||||
$iterator = new \RecursiveIteratorIterator($dirIterator);
|
||||
|
||||
|
||||
@ -38,6 +38,10 @@ class WebSocketDialogMsgTask extends AbstractTask
|
||||
{
|
||||
parent::__construct(...func_get_args());
|
||||
$this->id = $id;
|
||||
// 判断是否有Request方法,兼容go协程请求
|
||||
$this->ignoreFd = $ignoreFd;
|
||||
$this->client = [];
|
||||
if (method_exists(new Request,"header")) {
|
||||
$this->ignoreFd = $ignoreFd === null ? Request::header('fd') : $ignoreFd;
|
||||
$this->client = [
|
||||
'version' => Base::headerOrInput('version'),
|
||||
@ -45,6 +49,7 @@ class WebSocketDialogMsgTask extends AbstractTask
|
||||
'platform' => Base::headerOrInput('platform'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ignoreFd
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user