Поправки по результату тестирования

This commit is contained in:
Book Pauk
2020-12-24 16:33:44 +07:00
parent 1eac00f71c
commit d4f6536caa

View File

@@ -98,6 +98,7 @@ export default class BookParser {
*/ */
const getImageDimensions = (binaryId, binaryType, data) => { const getImageDimensions = (binaryId, binaryType, data) => {
return new Promise ((resolve, reject) => { (async() => { return new Promise ((resolve, reject) => { (async() => {
data = data.replace(/[\n\r\s]/g, '');
const i = new Image(); const i = new Image();
let resolved = false; let resolved = false;
i.onload = () => { i.onload = () => {
@@ -218,8 +219,8 @@ export default class BookParser {
if (tag == 'binary') { if (tag == 'binary') {
let attrs = sax.getAttrsSync(tail); let attrs = sax.getAttrsSync(tail);
binaryType = (attrs['content-type'] && attrs['content-type'].value ? attrs['content-type'].value : ''); binaryType = (attrs['content-type'] && attrs['content-type'].value ? attrs['content-type'].value : '');
binaryType = (binaryType == 'image/jpg' ? 'image/jpeg' : binaryType); binaryType = (binaryType == 'image/jpg' || binaryType == 'application/octet-stream' ? 'image/jpeg' : binaryType);
if (binaryType == 'image/jpeg' || binaryType == 'image/png' || binaryType == 'application/octet-stream') if (binaryType == 'image/jpeg' || binaryType == 'image/png')
binaryId = (attrs.id.value ? attrs.id.value : ''); binaryId = (attrs.id.value ? attrs.id.value : '');
} }
@@ -244,8 +245,11 @@ export default class BookParser {
} else {//external } else {//external
imageNum++; imageNum++;
if (!this.sets.isTesting) if (!this.sets.isTesting) {
dimPromises.push(getExternalImageDimensions(href)); dimPromises.push(getExternalImageDimensions(href));
} else {
dimPromises.push(this.sets.getExternalImageDimensions(this, href));
}
newParagraph(`<image href="${href}" num="${imageNum}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount); newParagraph(`<image href="${href}" num="${imageNum}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
this.images.push({paraIndex, num: imageNum, id, local, alt}); this.images.push({paraIndex, num: imageNum, id, local, alt});
@@ -492,8 +496,12 @@ export default class BookParser {
growParagraph(`${tOpen}${text}${tClose}`, text.length); growParagraph(`${tOpen}${text}${tClose}`, text.length);
} }
if (binaryId && !this.sets.isTesting) { if (binaryId) {
dimPromises.push(getImageDimensions(binaryId, binaryType, text)); if (!this.sets.isTesting) {
dimPromises.push(getImageDimensions(binaryId, binaryType, text));
} else {
dimPromises.push(this.sets.getImageDimensions(this, binaryId, binaryType, text));
}
} }
}; };