Исправление бага (#4)
This commit is contained in:
@@ -185,17 +185,14 @@ function initStatic(app, config) {
|
|||||||
filesPathStatic = `/book`;
|
filesPathStatic = `/book`;
|
||||||
filesDir = `${config.publicFilesDir}${config.filesPathStatic}`;
|
filesDir = `${config.publicFilesDir}${config.filesPathStatic}`;
|
||||||
*/
|
*/
|
||||||
const filesPath = `${config.filesPathStatic}/`;
|
|
||||||
//загрузка или восстановление файлов в /files, при необходимости
|
//загрузка или восстановление файлов в /files, при необходимости
|
||||||
app.use(async(req, res, next) => {
|
app.use(config.filesPathStatic, async(req, res, next) => {
|
||||||
if ((req.method !== 'GET' && req.method !== 'HEAD') ||
|
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
||||||
!(req.path.indexOf(filesPath) === 0)
|
|
||||||
) {
|
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.extname(req.path) == '') {
|
if (path.extname(req.path) == '') {
|
||||||
const bookFile = `${config.publicFilesDir}${req.path}`;
|
const bookFile = `${config.filesDir}${req.path}`;
|
||||||
const bookFileDesc = `${bookFile}.d.json`;
|
const bookFileDesc = `${bookFile}.d.json`;
|
||||||
|
|
||||||
let downFileName = '';
|
let downFileName = '';
|
||||||
@@ -216,8 +213,19 @@ function initStatic(app, config) {
|
|||||||
log(LM_ERR, e.message);
|
log(LM_ERR, e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downFileName)
|
if (downFileName) {
|
||||||
res.downFileName = downFileName;
|
res.downFileName = downFileName;
|
||||||
|
|
||||||
|
if (!req.acceptsEncodings('gzip')) {
|
||||||
|
//не принимает gzip, тогда распакуем
|
||||||
|
const rawFile = `${bookFile}.raw`;
|
||||||
|
if (!await fs.pathExists(rawFile))
|
||||||
|
await utils.gunzipFile(bookFile, rawFile);
|
||||||
|
|
||||||
|
req.url += '.raw';
|
||||||
|
res.rawFile = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
@@ -227,7 +235,9 @@ function initStatic(app, config) {
|
|||||||
app.use(config.filesPathStatic, express.static(config.filesDir, {
|
app.use(config.filesPathStatic, express.static(config.filesDir, {
|
||||||
setHeaders: (res) => {
|
setHeaders: (res) => {
|
||||||
if (res.downFileName) {
|
if (res.downFileName) {
|
||||||
res.set('Content-Encoding', 'gzip');
|
if (!res.rawFile)
|
||||||
|
res.set('Content-Encoding', 'gzip');
|
||||||
|
|
||||||
res.set('Content-Disposition', `inline; filename*=UTF-8''${encodeURIComponent(res.downFileName)}`);
|
res.set('Content-Disposition', `inline; filename*=UTF-8''${encodeURIComponent(res.downFileName)}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user