Изменение механизма работы с /tmp и /upload (начало)
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
require('tls').DEFAULT_MIN_VERSION = 'TLSv1';
|
require('tls').DEFAULT_MIN_VERSION = 'TLSv1';
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
|
||||||
const argv = require('minimist')(process.argv.slice(2));
|
const argv = require('minimist')(process.argv.slice(2));
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const compression = require('compression');
|
const compression = require('compression');
|
||||||
@@ -81,16 +80,6 @@ async function main() {
|
|||||||
if (devModule)
|
if (devModule)
|
||||||
devModule.logQueries(app);
|
devModule.logQueries(app);
|
||||||
|
|
||||||
app.use(express.static(serverConfig.publicDir, {
|
|
||||||
maxAge: '30d',
|
|
||||||
setHeaders: (res, filePath) => {
|
|
||||||
if (path.basename(path.dirname(filePath)) == 'tmp') {
|
|
||||||
res.set('Content-Type', 'application/xml');
|
|
||||||
res.set('Content-Encoding', 'gzip');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
require('./routes').initRoutes(app, wss, serverConfig);
|
require('./routes').initRoutes(app, wss, serverConfig);
|
||||||
|
|
||||||
if (devModule) {
|
if (devModule) {
|
||||||
|
|||||||
@@ -1,6 +1,57 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const multer = require('multer');
|
||||||
|
|
||||||
|
const ReaderWorker = require('./core/Reader/ReaderWorker');//singleton
|
||||||
|
|
||||||
const c = require('./controllers');
|
const c = require('./controllers');
|
||||||
const utils = require('./core/utils');
|
const utils = require('./core/utils');
|
||||||
const multer = require('multer');
|
|
||||||
|
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>${filePath}</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) {
|
function initRoutes(app, wss, config) {
|
||||||
//эксклюзив для update_checker
|
//эксклюзив для update_checker
|
||||||
@@ -8,6 +59,8 @@ function initRoutes(app, wss, config) {
|
|||||||
new c.BookUpdateCheckerController(wss, config);
|
new c.BookUpdateCheckerController(wss, config);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initStatic(app, config);
|
||||||
|
|
||||||
const misc = new c.MiscController(config);
|
const misc = new c.MiscController(config);
|
||||||
const reader = new c.ReaderController(config);
|
const reader = new c.ReaderController(config);
|
||||||
|
|||||||
Reference in New Issue
Block a user