Добавление отображения обложки (coverpage) в окне загруженных файлов
This commit is contained in:
@@ -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++;
|
||||
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user