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

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(); return next();
} }
if (path.extname(req.path) == '.json') if (path.extname(req.path) == '') {
return next(); const bookFile = `${config.publicFilesDir}${req.path}`;
const bookFileDesc = `${bookFile}.json`;
const bookFile = `${config.publicFilesDir}${req.path}`; let downFileName = '';
const bookFileDesc = `${bookFile}.json`; //восстановим из json-файла описания
try {
if (await fs.pathExists(bookFile) && await fs.pathExists(bookFileDesc)) {
await utils.touchFile(bookFile);
await utils.touchFile(bookFileDesc);
let downFileName = ''; let desc = await fs.readFile(bookFileDesc, 'utf8');
//восстановим из json-файла описания desc = JSON.parse(desc);
try { downFileName = desc.downFileName;
if (await fs.pathExists(bookFile) && await fs.pathExists(bookFileDesc)) { } else {
await utils.touchFile(bookFile); await fs.remove(bookFile);
await utils.touchFile(bookFileDesc); await fs.remove(bookFileDesc);
}
let desc = await fs.readFile(bookFileDesc, 'utf8'); } catch(e) {
desc = JSON.parse(desc); log(LM_ERR, e.message);
downFileName = desc.downFileName;
} else {
await fs.remove(bookFile);
await fs.remove(bookFileDesc);
} }
} catch(e) {
log(LM_ERR, e.message);
}
if (downFileName) if (downFileName)
res.downFileName = downFileName; res.downFileName = downFileName;
}
return next(); return next();
}); });