Рефакторинг
This commit is contained in:
@@ -41,6 +41,20 @@ class BookConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
decode(data) {
|
||||||
|
const charsetAll = chardet.detectAll(data.slice(0, 10000));
|
||||||
|
|
||||||
|
let selected = 'ISO-8859-1';
|
||||||
|
for (const charset of charsetAll) {
|
||||||
|
if (charset.name.indexOf('ISO-8859') < 0) {
|
||||||
|
selected = charset.name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return iconv.decode(data, selected);
|
||||||
|
}
|
||||||
|
|
||||||
async convertSamlib(data) {
|
async convertSamlib(data) {
|
||||||
let titleInfo = {};
|
let titleInfo = {};
|
||||||
let desc = {_n: 'description', 'title-info': titleInfo};
|
let desc = {_n: 'description', 'title-info': titleInfo};
|
||||||
@@ -180,17 +194,7 @@ class BookConverter {
|
|||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const charsetAll = chardet.detectAll(data.slice(0, 10000));
|
await parser.parse(this.decode(data));
|
||||||
|
|
||||||
let selected = 'ISO-8859-1';
|
|
||||||
for (const charset of charsetAll) {
|
|
||||||
if (charset.name.indexOf('ISO-8859') < 0) {
|
|
||||||
selected = charset.name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await parser.parse(iconv.decode(data, selected));
|
|
||||||
|
|
||||||
const title = (titleInfo['book-title'] ? titleInfo['book-title'] : '');
|
const title = (titleInfo['book-title'] ? titleInfo['book-title'] : '');
|
||||||
let author = '';
|
let author = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user