feat: 新增压缩下载完成后系统机器人提醒

This commit is contained in:
ganzizi 2023-12-05 18:55:50 +08:00
parent e4070e249d
commit faf5dec08a
3 changed files with 32 additions and 14 deletions

View File

@ -2,10 +2,10 @@
namespace App\Http\Controllers\Api; 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\Exceptions\ApiException;
use App\Models\AbstractModel; use App\Models\AbstractModel;
use App\Tasks\FilePackTask;
use App\Models\File; use App\Models\File;
use App\Models\FileContent; use App\Models\FileContent;
use App\Models\FileLink; use App\Models\FileLink;
@ -1020,15 +1020,15 @@ class FileController extends AbstractController
} }
$zip = new \ZipArchive(); $zip = new \ZipArchive();
$zipName = 'temp/download/' . date("Ym") . '/' . $user->userid . '/' . $downName; $zipName = 'tmp/file/' . date("Ym") . '/' . $user->userid . '/' . $downName;
$zipPath = storage_path('app/'.$zipName); $zipPath = public_path($zipName);
Base::makeDir(dirname($zipPath)); Base::makeDir(dirname($zipPath));
if ($zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) { if ($zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) {
return Base::retError('创建压缩文件失败'); return Base::retError('创建压缩文件失败');
} }
go(function() use ($zip, $files, $downName) { go(function() use ($user, $zip, $files, $downName, $zipName) {
Coroutine::sleep(0.1); Coroutine::sleep(0.1);
// 压缩进度 // 压缩进度
$progress = 0; $progress = 0;
@ -1051,6 +1051,19 @@ class FileController extends AbstractController
'progress' => 100 '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'); return Base::retSuccess('success');
@ -1074,8 +1087,8 @@ class FileController extends AbstractController
{ {
$user = User::auth(); $user = User::auth();
$downName = Request::input('name'); $downName = Request::input('name');
$zipName = 'temp/download/' . date("Ym") . '/' . $user->userid . '/' . $downName; $zipName = 'tmp/file/' . date("Ym") . '/' . $user->userid . '/' . $downName;
$zipPath = storage_path('app/'.$zipName); $zipPath = public_path($zipName);
if (!file_exists($zipPath)) { if (!file_exists($zipPath)) {
abort(403, "The file does not exist."); abort(403, "The file does not exist.");
} }

View File

@ -102,7 +102,7 @@ class DeleteTmpTask extends AbstractTask
*/ */
case 'file_pack': case 'file_pack':
{ {
$path = storage_path('app/temp/download/'); $path = public_path('tmp/file/');
$dirIterator = new \RecursiveDirectoryIterator($path); $dirIterator = new \RecursiveDirectoryIterator($path);
$iterator = new \RecursiveIteratorIterator($dirIterator); $iterator = new \RecursiveIteratorIterator($dirIterator);

View File

@ -38,12 +38,17 @@ class WebSocketDialogMsgTask extends AbstractTask
{ {
parent::__construct(...func_get_args()); parent::__construct(...func_get_args());
$this->id = $id; $this->id = $id;
$this->ignoreFd = $ignoreFd === null ? Request::header('fd') : $ignoreFd; // 判断是否有Request方法兼容go协程请求
$this->client = [ $this->ignoreFd = $ignoreFd;
'version' => Base::headerOrInput('version'), $this->client = [];
'language' => Base::headerOrInput('language'), if (method_exists(new Request,"header")) {
'platform' => Base::headerOrInput('platform'), $this->ignoreFd = $ignoreFd === null ? Request::header('fd') : $ignoreFd;
]; $this->client = [
'version' => Base::headerOrInput('version'),
'language' => Base::headerOrInput('language'),
'platform' => Base::headerOrInput('platform'),
];
}
} }
/** /**