From b644a65f22c9d98badd3ccaee91ec0789b45d77b Mon Sep 17 00:00:00 2001 From: weifashi <605403358@qq.com> Date: Mon, 20 Nov 2023 15:19:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=201.=20=E4=BF=AE=E5=A4=8D=20windows?= =?UTF-8?q?=E7=AB=AF=20=20=E5=8F=B3=E9=94=AE=E5=8F=91=E9=80=81=20=E6=98=AF?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E5=8F=91=E9=80=81=E4=BA=86=EF=BC=8C=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=87=BA=E7=8E=B0=E4=BD=BF=E7=94=A8md=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8F=91=E9=80=81=20=202.=E5=85=B6=E4=BB=96bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/FileController.php | 103 ++++++++---------- app/Services/WebSocketService.php | 7 +- config/laravels.php | 2 +- language/original-api.txt | 2 +- .../manage/components/ChatInput/index.vue | 3 + resources/assets/js/pages/manage/file.vue | 20 ++-- 6 files changed, 69 insertions(+), 68 deletions(-) diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index 15b1ffbda..989648fa9 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -975,49 +975,7 @@ class FileController extends AbstractController } /** - * @api {get} api/file/download/check 19. 检测下载 - * - * @apiDescription 需要token身份 - * @apiVersion 1.0.0 - * @apiGroup file - * @apiName download__check - * - * @apiParam {Array} [ids] 文件ID,格式: [id, id2, id3] - * - * @apiSuccess {Number} ret 返回状态码(1正确、0错误) - * @apiSuccess {String} msg 返回信息(错误描述) - * @apiSuccess {Object} data 返回数据 - */ - public function download__check(){ - $user = User::auth(); - $ids = Request::input('ids'); - - if (!is_array($ids) || empty($ids)) { - return Base::retError('请选择下载的文件或文件夹'); - } - - if (count($ids) > 100) { - return Base::retError('一次最多只能下载100个文件或文件夹'); - } - - $files = []; - $totalSize = 0; - AbstractModel::transaction(function() use ($user, $ids, &$files, &$totalSize) { - foreach ($ids as $k => $id) { - $files[] = File::getFilesTree(intval($id), $user, 1); - $totalSize += $files[$k]->totalSize; - } - }); - - if ($totalSize > File::zipMaxSize) { - throw new ApiException('文件总大小已超过1GB,请分批下载'); - } - - return Base::retSuccess('success'); - } - - /** - * @api {get} api/file/download/pack 20. 打包文件 + * @api {get} api/file/download/pack 19. 打包文件 * * @apiDescription 需要token身份 * @apiVersion 1.0.0 @@ -1038,31 +996,66 @@ class FileController extends AbstractController $downName = Request::input('name'); if (!is_array($ids) || empty($ids)) { - abort(403, "Please select the file or folder to download."); + return Base::retError('请选择下载的文件或文件夹'); } if (count($ids) > 100) { - abort(403, "You can download a maximum of 100 files or folders at a time."); + return Base::retError('一次最多可以下载100个文件或文件夹'); + } + if (count($ids) > 100) { + return Base::retError('一次最多可以下载100个文件或文件夹'); } $files = []; $totalSize = 0; - AbstractModel::transaction(function() use ($user, $ids, &$files, &$totalSize) { - foreach ($ids as $k => $id) { - $files[] = File::getFilesTree(intval($id), $user, 1); - $totalSize += $files[$k]->totalSize; + + foreach ($ids as $k => $id) { + $files[] = File::getFilesTree(intval($id), $user, 1); + $totalSize += $files[$k]->totalSize; + } + + if ($totalSize > File::zipMaxSize) { + return Base::retError('文件总大小已超过1GB,请分批下载'); + } + + $zip = new \ZipArchive(); + $zipName = 'temp/download/' . date("Ym") . '/' . $user->userid . '/' . $downName; + $zipPath = storage_path('app/'.$zipName); + Base::makeDir(dirname($zipPath)); + + if ($zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) { + return Base::retError('创建压缩文件失败'); + } + + go(function() use ($zip, $files, $downName) { + Coroutine::sleep(0.1); + // 压缩进度 + $progress = 0; + $zip->registerProgressCallback(0.05, function($ratio) use ($downName, &$progress) { + $progress = round($ratio * 100); + File::filePushMsg('compress', [ + 'name'=> $downName, + 'progress' => $progress + ]); + }); + // + foreach ($files as $file) { + File::addFileTreeToZip($zip, $file); + } + $zip->close(); + // + if ($progress < 100) { + File::filePushMsg('compress', [ + 'name'=> $downName, + 'progress' => 100 + ]); } }); - if ($totalSize > File::zipMaxSize) { - abort(403, "The total size of the file exceeds 1GB. Please download it in batches."); - } - - Task::deliver(new FilePackTask($user, $files, $downName)); return Base::retSuccess('success'); } /** - * @api {get} api/file/download/confirm 21. 确认下载 + * @api {get} api/file/download/confirm 20. 确认下载 * * @apiDescription 需要token身份 * @apiVersion 1.0.0 diff --git a/app/Services/WebSocketService.php b/app/Services/WebSocketService.php index a83dde8db..d9ce8d127 100644 --- a/app/Services/WebSocketService.php +++ b/app/Services/WebSocketService.php @@ -172,8 +172,11 @@ class WebSocketService implements WebSocketHandlerInterface */ public function onClose(Server $server, $fd, $reactorId) { - Task::deliver(new LineTask($this->getUserid($fd), false)); // 通知离线 - $this->deleteUser($fd); + $userid = $this->getUserid($fd); + if($userid){ + Task::deliver(new LineTask($userid, false)); // 通知离线 + $this->deleteUser($fd); + } } /** ****************************************************************************** */ diff --git a/config/laravels.php b/config/laravels.php index 5c0cc00e0..bad61e7a8 100644 --- a/config/laravels.php +++ b/config/laravels.php @@ -306,7 +306,7 @@ return [ 'reload_async' => true, 'max_wait_time' => 60, 'enable_reuse_port' => true, - 'enable_coroutine' => false, + 'enable_coroutine' => true, 'upload_tmp_dir' => @is_writable('/dev/shm/') ? '/dev/shm' : '/tmp', 'http_compression' => false, ], diff --git a/language/original-api.txt b/language/original-api.txt index 0f609bb85..6c645b314 100644 --- a/language/original-api.txt +++ b/language/original-api.txt @@ -479,4 +479,4 @@ Api接口文档 文件总大小已超过1GB,请分批下载 保存任务详情至文件失败 保存任务详情至文件失败,请重试 -移动成功 \ No newline at end of file +移动成功 diff --git a/resources/assets/js/pages/manage/components/ChatInput/index.vue b/resources/assets/js/pages/manage/components/ChatInput/index.vue index 2f0a6c21c..b82ece712 100755 --- a/resources/assets/js/pages/manage/components/ChatInput/index.vue +++ b/resources/assets/js/pages/manage/components/ChatInput/index.vue @@ -1030,6 +1030,9 @@ export default { if ((event.button === undefined || event.button === 0) && this.startRecord()) { return; } + if (event.button === 2){ + this.showMenu = true; + } break; case 'move': diff --git a/resources/assets/js/pages/manage/file.vue b/resources/assets/js/pages/manage/file.vue index e36665f53..e7a3c43b9 100644 --- a/resources/assets/js/pages/manage/file.vue +++ b/resources/assets/js/pages/manage/file.vue @@ -1477,10 +1477,12 @@ export default { updatePackProgress () { this.packList.forEach(file=>{ const pack = this.filePackLists.find(({name}) => name == file.name) - file.percentage = Math.max(1, pack.progress); - if (file.status != 'finished' && file.percentage >= 100) { - file.status = 'finished'; - this.downloadPackFile(file.name); + if(pack){ + file.percentage = Math.max(1, pack.progress); + if (file.status != 'finished' && file.percentage >= 100) { + file.status = 'finished'; + this.downloadPackFile(file.name); + } } }) }, @@ -1514,16 +1516,16 @@ export default { content: `你确定要打包下载${fileName}吗?`, okText: '确定', onOk: async () => { + if( this.packList.find(({ status }) => status === 'packing') ){ + $A.messageWarning("请等待打包完成"); + return; + } try { - await this.$store.dispatch("call", { - url: 'file/download/check', - data: { ids }, - }); - this.startPack(filePackName); await this.$store.dispatch("call", { url: 'file/download/pack', data: { ids, name: filePackName }, }); + this.startPack(filePackName); } catch ({ msg }) { $A.modalError(msg); }