From 8ee1b98a12e4cbf871b0279a3270b1cc38d67fe8 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 9 Nov 2022 23:58:08 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=82=D0=B4=D0=B0=D1=87=D0=B0=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=82=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/index.js | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/server/index.js b/server/index.js index 99383c1..15e387f 100644 --- a/server/index.js +++ b/server/index.js @@ -189,32 +189,31 @@ function initStatic(app, config) { return next(); } - if (path.extname(req.path) == '.json') - return next(); + if (path.extname(req.path) == '') { + const bookFile = `${config.publicFilesDir}${req.path}`; + const bookFileDesc = `${bookFile}.json`; - const bookFile = `${config.publicFilesDir}${req.path}`; - const bookFileDesc = `${bookFile}.json`; + let downFileName = ''; + //восстановим из json-файла описания + try { + if (await fs.pathExists(bookFile) && await fs.pathExists(bookFileDesc)) { + await utils.touchFile(bookFile); + await utils.touchFile(bookFileDesc); - let downFileName = ''; - //восстановим из json-файла описания - try { - if (await fs.pathExists(bookFile) && await fs.pathExists(bookFileDesc)) { - await utils.touchFile(bookFile); - await utils.touchFile(bookFileDesc); - - let desc = await fs.readFile(bookFileDesc, 'utf8'); - desc = JSON.parse(desc); - downFileName = desc.downFileName; - } else { - await fs.remove(bookFile); - await fs.remove(bookFileDesc); + let desc = await fs.readFile(bookFileDesc, 'utf8'); + desc = JSON.parse(desc); + downFileName = desc.downFileName; + } else { + await fs.remove(bookFile); + await fs.remove(bookFileDesc); + } + } catch(e) { + log(LM_ERR, e.message); } - } catch(e) { - log(LM_ERR, e.message); - } - if (downFileName) - res.downFileName = downFileName; + if (downFileName) + res.downFileName = downFileName; + } return next(); });