Browse Source

Работа над BookInfoDialog

Book Pauk 2 years ago
parent
commit
40f72d17e6
2 changed files with 19 additions and 12 deletions
  1. 6 7
      server/core/WebWorker.js
  2. 13 5
      server/core/xml/Fb2Parser.js

+ 6 - 7
server/core/WebWorker.js

@@ -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 {

+ 13 - 5
server/core/xml/Fb2Parser.js

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