Поправлена отдача статики

This commit is contained in:
Book Pauk
2022-11-09 23:58:08 +07:00
parent ffc65ab944
commit 8ee1b98a12

View File

@@ -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();
});