From 24d609d8f17ced4628b7d13f9496a84bdcb51153 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 12 Apr 2023 17:14:12 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81=20inpx,?= =?UTF-8?q?=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BF=D0=BE=D0=BD?= =?UTF-8?q?=D0=B8=D0=BC=D0=B0=D0=B5=D1=82=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B?= =?UTF-8?q?=20=D0=B2=20=D0=BA=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3=D0=B0?= =?UTF-8?q?=D1=85=20(=D0=B1=D0=B5=D0=B7=20zip-=D0=B0=D1=80=D1=85=D0=B8?= =?UTF-8?q?=D0=B2=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/WebWorker.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/server/core/WebWorker.js b/server/core/WebWorker.js index 317ee89..2cc3b95 100644 --- a/server/core/WebWorker.js +++ b/server/core/WebWorker.js @@ -372,17 +372,28 @@ class WebWorker { async extractBook(bookPath) { const outFile = `${this.config.tempDir}/${utils.randomHexString(30)}`; - const folder = `${this.config.libDir}/${path.dirname(bookPath)}`; - const file = path.basename(bookPath); + bookPath = bookPath.replace(/\\/g, '/').replace(/\/\//g, '/'); - const zipReader = new ZipReader(); - await zipReader.open(folder); + const i = bookPath.indexOf('/'); + const folder = `${this.config.libDir}/${(i >= 0 ? bookPath.substring(0, i) : bookPath )}`; + const file = (i >= 0 ? bookPath.substring(i + 1) : '' ); - try { - await zipReader.extractToFile(file, outFile); + const fullPath = `${folder}/${file}`; + + if (!file || await fs.pathExists(fullPath)) {// файл есть на диске + + await fs.copy(fullPath, outFile); return outFile; - } finally { - await zipReader.close(); + } else {// файл в zip-архиве + const zipReader = new ZipReader(); + await zipReader.open(folder); + + try { + await zipReader.extractToFile(file, outFile); + return outFile; + } finally { + await zipReader.close(); + } } }