Добавление отображения обложки (coverpage) в окне загруженных файлов

This commit is contained in:
Book Pauk
2022-07-15 00:47:24 +07:00
parent b56f45694e
commit 7fc98fc7da
6 changed files with 92 additions and 5 deletions

View File

@@ -85,6 +85,7 @@ export default class BookParser {
let binaryId = '';
let binaryType = '';
let dimPromises = [];
this.coverPageId = '';
//оглавление
this.contents = [];
@@ -289,7 +290,7 @@ export default class BookParser {
const href = attrs.href.value;
const alt = (attrs.alt && attrs.alt.value ? attrs.alt.value : '');
const {id, local} = this.imageHrefToId(href);
if (href[0] == '#') {//local
if (local) {//local
imageNum++;
if (inPara && !this.sets.showInlineImagesInCenter && !center)
@@ -301,6 +302,11 @@ export default class BookParser {
if (inPara && this.sets.showInlineImagesInCenter)
newParagraph();
//coverpage
if (path == '/fictionbook/description/title-info/coverpage/image') {
this.coverPageId = id;
}
} else {//external
imageNum++;

View File

@@ -2,8 +2,9 @@ import localForage from 'localforage';
import path from 'path-browserify';
import _ from 'lodash';
import * as utils from '../../../share/utils';
import BookParser from './BookParser';
import readerApi from '../../../api/reader';
import * as utils from '../../../share/utils';
const maxDataSize = 500*1024*1024;//compressed bytes
const maxRecentLength = 5000;
@@ -345,9 +346,27 @@ class BookManager {
const parsed = new BookParser(this.settings);
const parsedMeta = await parsed.parse(data, callback);
//cover page
let coverPageUrl = '';
if (parsed.coverPageId && parsed.binary[parsed.coverPageId]) {
const bin = parsed.binary[parsed.coverPageId];
const dataUrl = await utils.resizeImage(`data:${bin.type};base64,${bin.data}`);
//отправим dataUrl на сервер в /upload
try {
await readerApi.uploadFileBuf(dataUrl, (url) => {
coverPageUrl = url;
});
} catch (e) {
console.error(e);
}
}
const result = Object.assign({}, meta, parsedMeta, {
length: data.length,
textLength: parsed.textLength,
coverPageUrl,
parsed
});