From c6300222eacb0e3e90fca73e361e878ccf626e8c Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sat, 16 Jul 2022 17:54:27 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B9=20=D1=80?= =?UTF-8?q?=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/routes.js | 88 ++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/server/routes.js b/server/routes.js index 968232f2..9f56496f 100644 --- a/server/routes.js +++ b/server/routes.js @@ -9,50 +9,6 @@ const ReaderWorker = require('./core/Reader/ReaderWorker');//singleton const c = require('./controllers'); const utils = require('./core/utils'); -function initStatic(app, config) { - const readerWorker = new ReaderWorker(config); - - //восстановление файлов в /tmp и /upload из webdav-storage, при необходимости - app.use(async(req, res, next) => { - if ((req.method !== 'GET' && req.method !== 'HEAD') || - !(req.path.indexOf('/tmp/') === 0 || req.path.indexOf('/upload/') === 0) - ) { - return next(); - } - - const filePath = `${config.publicDir}${req.path}`; - - //восстановим - if (!await fs.pathExists(filePath)) { - /*const zlib = require('zlib'); - const gzipBuffer = async(buf) => { - return new Promise((resolve, reject) => { - zlib.gzip(buf, {level: 1}, (err, result) => { - if (err) reject(err); - resolve(result); - }); - }); - }; - - await fs.writeFile(filePath, await gzipBuffer(`${filePath}`));*/ - } - - return next(); - }); - - const tmpDir = `${config.publicDir}/tmp`; - app.use(express.static(config.publicDir, { - maxAge: '30d', - - setHeaders: (res, filePath) => { - if (path.dirname(filePath) == tmpDir) { - res.set('Content-Type', 'application/xml'); - res.set('Content-Encoding', 'gzip'); - } - }, - })); -} - function initRoutes(app, wss, config) { //эксклюзив для update_checker if (config.mode === 'book_update_checker') { @@ -136,6 +92,50 @@ function initRoutes(app, wss, config) { } } +function initStatic(app, config) { + const readerWorker = new ReaderWorker(config); + + //восстановление файлов в /tmp и /upload из webdav-storage, при необходимости + app.use(async(req, res, next) => { + if ((req.method !== 'GET' && req.method !== 'HEAD') || + !(req.path.indexOf('/tmp/') === 0 || req.path.indexOf('/upload/') === 0) + ) { + return next(); + } + + const filePath = `${config.publicDir}${req.path}`; + + //восстановим + if (!await fs.pathExists(filePath)) { + /*const zlib = require('zlib'); + const gzipBuffer = async(buf) => { + return new Promise((resolve, reject) => { + zlib.gzip(buf, {level: 1}, (err, result) => { + if (err) reject(err); + resolve(result); + }); + }); + }; + + await fs.writeFile(filePath, await gzipBuffer(`${filePath}`));*/ + } + + return next(); + }); + + const tmpDir = `${config.publicDir}/tmp`; + app.use(express.static(config.publicDir, { + maxAge: '30d', + + setHeaders: (res, filePath) => { + if (path.dirname(filePath) == tmpDir) { + res.set('Content-Type', 'application/xml'); + res.set('Content-Encoding', 'gzip'); + } + }, + })); +} + module.exports = { initRoutes }