Browse Source

Поправки багов

Book Pauk 6 years ago
parent
commit
ab29c80dab
2 changed files with 16 additions and 3 deletions
  1. 8 1
      server/core/BookConverter/index.js
  2. 8 2
      server/core/FileDownloader.js

+ 8 - 1
server/core/BookConverter/index.js

@@ -231,6 +231,7 @@ class BookConverter {
         let tag = '';// eslint-disable-line no-unused-vars
         let tag = '';// eslint-disable-line no-unused-vars
 
 
         let inText = false;
         let inText = false;
+        let textFound = false;
         let node = {_a: pars};
         let node = {_a: pars};
 
 
         let inPara = false;
         let inPara = false;
@@ -374,8 +375,10 @@ class BookConverter {
         };
         };
 
 
         const onComment = (text) => {// eslint-disable-line no-unused-vars
         const onComment = (text) => {// eslint-disable-line no-unused-vars
-            if (text == '--------- Собственно произведение -------------')
+            if (text == '--------- Собственно произведение -------------') {
                 inText = true;
                 inText = true;
+                textFound = true;
+            }
             if (text == '-----------------------------------------------')
             if (text == '-----------------------------------------------')
                 inText = false;
                 inText = false;
         };
         };
@@ -418,6 +421,10 @@ class BookConverter {
             innerCut: new Set(['head', 'script', 'style'])
             innerCut: new Set(['head', 'script', 'style'])
         });
         });
 
 
+        //текст не найден на странице, обрабатываем как html
+        if (!textFound)
+            return this.convertHtml(data);
+
         const title = (titleInfo['book-title'] ? titleInfo['book-title'] : '');
         const title = (titleInfo['book-title'] ? titleInfo['book-title'] : '');
         let author = '';
         let author = '';
         if (titleInfo.author) {
         if (titleInfo.author) {

+ 8 - 2
server/core/FileDownloader.js

@@ -8,8 +8,14 @@ class FileDownloader {
 
 
     async load(url, callback) {
     async load(url, callback) {
         let errMes = '';
         let errMes = '';
+        const options = {
+            encoding: null,
+            headers: {
+                'user-agent': 'Mozilla/5.0 (X11; HasCodingOs 1.0; Linux x64) AppleWebKit/637.36 (KHTML, like Gecko) Chrome/70.0.3112.101 Safari/637.36 HasBrowser/5.0'
+            }
+        };
 
 
-        const response = await got(url, {method: 'HEAD'});
+        const response = await got(url, Object.assign({}, options, {method: 'HEAD'}));
 
 
         let estSize = 0;
         let estSize = 0;
         if (response.headers['content-length']) {
         if (response.headers['content-length']) {
@@ -17,7 +23,7 @@ class FileDownloader {
         }
         }
 
 
         let prevProg = 0;
         let prevProg = 0;
-        const request = got(url, {encoding: null}).on('downloadProgress', progress => {
+        const request = got(url, options).on('downloadProgress', progress => {
             if (progress.transferred > maxDownloadSize) {
             if (progress.transferred > maxDownloadSize) {
                 errMes = 'file too big';
                 errMes = 'file too big';
                 request.cancel();
                 request.cancel();