Работа над BookInfoDialog

This commit is contained in:
Book Pauk
2022-11-08 22:07:11 +07:00
parent 4b5949e3bc
commit 40f72d17e6
2 changed files with 19 additions and 12 deletions

View File

@@ -473,15 +473,14 @@ class WebWorker {
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 = '';
bookInfo.fb2 = false;
if (book.ext == 'fb2') {
const {desc, cover} = await this.fb2Parser.getDescAndCover(bookFile);
bookInfo.fb2 = desc;
}
await fs.writeFile(bookFileInfo, JSON.stringify(bookInfo, null, 2));
} else {

View File

@@ -2,7 +2,7 @@ const fs = require('fs-extra');
const iconv = require('iconv-lite');
const textUtils = require('./textUtils');
const xmlParser = require('./xmlParser');
const XmlParser = require('./XmlParser');
const utils = require('../utils');
class Fb2Parser {
@@ -55,12 +55,20 @@ class Fb2Parser {
data = await utils.gunzipBuffer(data);
//data = this.checkEncoding(data);
const result = xmlParser.parseXml(data.toString(), true, (route) => {
console.log(route);
return true;
const xml = new XmlParser();
xml.fromString(data.toString(), {
lowerCase: true,
pickNode: route => route.indexOf('fictionbook/body') !== 0,
});
return xmlParser.simplifyXmlParsed(result);
let cover = null;
//console.log(xml.toString());
//xml.each(node => console.log(node.name));
const desc = xml.$$('description').toObject();
return {desc, cover};
}
}