Former-commit-id: 078ce19e042b9ac368de0f112d2ec2842f17e84b
This commit is contained in:
troyeguo
2021-12-29 18:41:24 +08:00
parent 83a8296d48
commit 4eac95b9bc
5 changed files with 14 additions and 20 deletions

View File

@@ -8,11 +8,7 @@ import iconv from "iconv-lite";
import chardet from "chardet";
import rtfToHTML from "@iarna/rtf-to-html";
import PopupMenu from "../../components/popups/popupMenu";
import {
xmlBookTagFilter,
xmlBookToObj,
xmlImageHandler,
} from "../../utils/fileUtils/xmlUtil";
import { xmlBookParser } from "../../utils/fileUtils/xmlUtil";
import StorageUtil from "../../utils/storageUtil";
import RecordLocation from "../../utils/readUtils/recordLocation";
import { mimetype } from "../../constants/mimetype";
@@ -162,9 +158,9 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
if (this.props.currentBook.format.startsWith("CB")) {
this.setState({
chapter:
this.props.htmlBook.chapters[parseInt(bookLocation.count || "0")]
this.props.htmlBook.chapters[parseInt(bookLocation.count) || 0]
.label,
chapterIndex: parseInt(bookLocation.count || "0"),
chapterIndex: parseInt(bookLocation.count) || 0,
});
} else {
this.setState({
@@ -217,7 +213,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
);
await rendition.renderTo(
document.getElementsByClassName("html-viewer-page")[0],
parseInt(bookLocation.count || "0")
parseInt(bookLocation.count) || 0
);
this.handleRest(rendition);
};
@@ -236,7 +232,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
);
await rendition.renderTo(
document.getElementsByClassName("html-viewer-page")[0],
parseInt(bookLocation.count || "0")
parseInt(bookLocation.count) || 0
);
this.handleRest(rendition);
});
@@ -256,7 +252,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
);
await rendition.renderTo(
document.getElementsByClassName("html-viewer-page")[0],
parseInt(bookLocation.count || "0")
parseInt(bookLocation.count) || 0
);
this.handleRest(rendition);
},
@@ -394,9 +390,8 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
Buffer.from(result),
this.props.currentBook.charset || charset || "utf8"
);
let bookObj = "";
bookObj += xmlBookTagFilter(Buffer.from(result), fb2Str);
let bookObj = xmlBookParser(Buffer.from(result), fb2Str);
console.log(bookObj);
let rendition = new StrRender(
bookObj,
this.state.readerMode,

View File

@@ -12,7 +12,7 @@ class LoadingPage extends React.Component<LoadingPageProps> {
let arr: number[] = [];
for (
let i = 0;
i < parseInt(StorageUtil.getReaderConfig("totalBooks") || "0");
i < parseInt(StorageUtil.getReaderConfig("totalBooks")) || 0;
i++
) {
arr.push(i);

View File

@@ -31,8 +31,7 @@ class Manager extends React.Component<ManagerProps, ManagerState> {
constructor(props: ManagerProps) {
super(props);
this.state = {
totalBooks:
parseInt(StorageUtil.getReaderConfig("totalBooks") || "0") || 0,
totalBooks: parseInt(StorageUtil.getReaderConfig("totalBooks")) || 0,
favoriteBooks: Object.keys(AddFavorite.getAllFavorite()).length,
isAuthed: false,
isError: false,

View File

@@ -34,7 +34,7 @@ export const xmlBookToObj = (xml) => {
return informBook;
};
export const xmlBookTagFilter = (xml: any, bookString: string) => {
export const xmlBookParser = (xml: any, bookString: string) => {
var regExpTagDelete = /<epigraph>|<\/epigraph>|<empty-line\/>|/gi;
var regExpTitleOpen = /<title>/gi;
var regExpTitleClose = /<\/title>/gi;
@@ -67,7 +67,7 @@ export const xmlImageHandler = (xml: any, bookString: string) => {
for (let j = 0; j < fictionBook.binary.length; j++) {
if (strArr[i].startsWith(fictionBook.binary[j]["$"].id)) {
strArr[i] =
'<img alt="poster" src="' +
'<img alt="poster" width="100%" src="' +
"data:image/jpeg;base64," +
fictionBook.binary[j]["_"] +
strArr[i].slice(fictionBook.binary[j]["$"].id.length);