Работа над карточкой "Информация о книге"

This commit is contained in:
Book Pauk
2022-11-07 16:24:52 +07:00
parent 2ae7f21bc8
commit 02f276ca6b
2 changed files with 63 additions and 5 deletions

View File

@@ -15,6 +15,7 @@ const ayncExit = new (require('./AsyncExit'))();
const log = new (require('./AppLogger'))().log;//singleton
const utils = require('./utils');
const genreTree = require('./genres');
const Fb2Parser = require('./xml/Fb2Parser');
//server states
const ssNormal = 'normal';
@@ -44,6 +45,7 @@ class WebWorker {
}
this.inpxHashCreator = new InpxHashCreator(config);
this.fb2Parser = new Fb2Parser();
this.inpxFileHash = '';
this.wState = this.workerState.getControl('server_state');
@@ -462,12 +464,31 @@ class WebWorker {
try {
const db = this.db;
const bookInfo = await this.getBookLink(bookId);
let bookInfo = await this.getBookLink(bookId);
const hash = path.basename(bookInfo.link);
const bookFile = `${this.config.filesDir}/${hash}`;
const bookFileInfo = `${bookFile}.info`;
const rows = await db.select({table: 'book', where: `@@id(${db.esc(bookId)})`});
bookInfo.book = rows[0];
bookInfo.fb2 = {};
bookInfo.cover = '';
if (!await fs.pathExists(bookFileInfo)) {
const rows = await db.select({table: 'book', where: `@@id(${db.esc(bookId)})`});
const book = rows[0];
let fb2 = false;
if (book.ext == 'fb2') {
const parsedFb2 = await this.fb2Parser.getDescAndCover(bookFile);
fb2 = parsedFb2;
}
bookInfo.book = book;
bookInfo.fb2 = fb2;
bookInfo.cover = '';
await fs.writeFile(bookFileInfo, JSON.stringify(bookInfo, null, 2));
} else {
await utils.touchFile(bookFileInfo);
const info = fs.readFile(bookFileInfo, 'utf-8');
bookInfo = JSON.parse(info);
}
return {bookInfo};
} catch(e) {