From e685f136e1e35961763a572379e31450b3af1dd0 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 18 Nov 2022 20:45:38 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BC=D0=B5=D0=BB=D0=BA=D0=BE=D0=B3=D0=BE=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=B3=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/WebWorker.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/server/core/WebWorker.js b/server/core/WebWorker.js index 547f55d..6f02b64 100644 --- a/server/core/WebWorker.js +++ b/server/core/WebWorker.js @@ -469,14 +469,14 @@ class WebWorker { const bookFile = `${this.config.filesDir}/${hash}`; const bookFileInfo = `${bookFile}.i.json`; + let rows = await db.select({table: 'book', where: `@@hash('_uid', ${db.esc(bookUid)})`}); + if (!rows.length) + throw new Error('404 Файл не найден'); + const book = rows[0]; + const restoreBookInfo = async(info) => { const result = {}; - let rows = await db.select({table: 'book', where: `@@hash('_uid', ${db.esc(bookUid)})`}); - if (!rows.length) - throw new Error('404 Файл не найден'); - const book = rows[0]; - result.book = book; result.cover = ''; result.fb2 = false; @@ -493,7 +493,8 @@ class WebWorker { } } - Object.assign(info ,result); + Object.assign(info, result); + await fs.writeFile(bookFileInfo, JSON.stringify(info)); if (this.config.branch === 'development') { @@ -513,7 +514,7 @@ class WebWorker { if (tmpInfo.cover) coverFile = `${this.config.publicFilesDir}${tmpInfo.cover}`; - if (coverFile && !await fs.pathExists(coverFile)) { + if (book.id != tmpInfo.book.id || (coverFile && !await fs.pathExists(coverFile))) { await restoreBookInfo(bookInfo); } else { bookInfo = tmpInfo;