From 037d1aa022318b666ff65fd54f93d777cc6a7337 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Tue, 1 Nov 2022 01:53:39 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B1=D0=B0=D0=B3=D0=BE=D0=B2=20?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=D1=87=D0=B8=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20=D0=B2=20=D1=80=D0=B5=D0=B6?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=20RemoteLib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/RemoteLib.js | 2 +- server/core/WebWorker.js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/server/core/RemoteLib.js b/server/core/RemoteLib.js index 5bd0238..122cdd9 100644 --- a/server/core/RemoteLib.js +++ b/server/core/RemoteLib.js @@ -65,7 +65,7 @@ class RemoteLib { const buf = await this.down.load(`${this.remoteHost}${link}`, {decompress: false}); - const publicPath = `${this.config.publicDir}${link}`; + const publicPath = `${this.config.publicFilesDir}${link}`; await fs.writeFile(publicPath, buf); diff --git a/server/core/WebWorker.js b/server/core/WebWorker.js index 03c3a04..05ee501 100644 --- a/server/core/WebWorker.js +++ b/server/core/WebWorker.js @@ -370,12 +370,14 @@ class WebWorker { const bookFileDesc = `${bookFile}.json`; if (!await fs.pathExists(bookFile) || !await fs.pathExists(bookFileDesc)) { - await fs.ensureDir(path.dirname(bookFile)); - - const tmpFile = `${this.config.tempDir}/${utils.randomHexString(30)}`; - await utils.gzipFile(extractedFile, tmpFile, 4); - await fs.remove(extractedFile); - await fs.move(tmpFile, bookFile, {overwrite: true}); + if (!await fs.pathExists(bookFile) && extractedFile) { + const tmpFile = `${this.config.tempDir}/${utils.randomHexString(30)}`; + await utils.gzipFile(extractedFile, tmpFile, 4); + await fs.remove(extractedFile); + await fs.move(tmpFile, bookFile, {overwrite: true}); + } else { + await utils.touchFile(bookFile); + } await fs.writeFile(bookFileDesc, JSON.stringify({bookPath, downFileName})); } else { @@ -411,9 +413,10 @@ class WebWorker { const rows = await db.select({table: 'file_hash', where: `@@id(${db.esc(bookPath)})`}); if (rows.length) {//хеш найден по bookPath const hash = rows[0].hash; - const bookFileDesc = `${this.config.filesDir}/${hash}.json`; + const bookFile = `${this.config.filesDir}/${hash}`; + const bookFileDesc = `${bookFile}.json`; - if (await fs.pathExists(bookFileDesc)) { + if (await fs.pathExists(bookFile) && await fs.pathExists(bookFileDesc)) { link = `${this.config.filesPathStatic}/${hash}`; } }