upgrade deps and some minor fixes

This commit is contained in:
daniel-j 2020-01-16 11:09:13 +01:00
parent ed691a43a9
commit a58f4d5254
6 changed files with 1004 additions and 618 deletions

1564
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{ {
"name": "fimfic2epub", "name": "fimfic2epub",
"version": "1.7.38", "version": "1.7.39",
"description": "Tool to generate improved EPUB ebooks from Fimfiction stories", "description": "Tool to generate improved EPUB ebooks from Fimfiction stories",
"author": "djazz", "author": "djazz",
"license": "MIT", "license": "MIT",
@ -22,13 +22,13 @@
"LICENSE" "LICENSE"
], ],
"dependencies": { "dependencies": {
"canvas": "^2.6.0", "canvas": "^2.6.1",
"commander": "^3.0.2", "commander": "^4.1.0",
"crc-32": "^1.2.0", "crc-32": "^1.2.0",
"detect-node": "^2.0.4", "detect-node": "^2.0.4",
"elementtree": "^0.1.7", "elementtree": "^0.1.7",
"escape-string-regexp": "^2.0.0", "escape-string-regexp": "^2.0.0",
"file-type": "^12.3.0", "file-type": "^13.1.0",
"fonteditor-core": "^1.0.5", "fonteditor-core": "^1.0.5",
"html-entities": "^1.2.1", "html-entities": "^1.2.1",
"html-to-text": "^5.1.1", "html-to-text": "^5.1.1",
@ -43,20 +43,20 @@
"request": "^2.88.0", "request": "^2.88.0",
"sanitize-filename": "^1.6.3", "sanitize-filename": "^1.6.3",
"syllable": "^4.0.0", "syllable": "^4.0.0",
"twemoji": "^12.1.3", "twemoji": "^12.1.4",
"typogr": "^0.6.8", "typogr": "^0.6.8",
"url-regex": "^5.0.0", "url-regex": "^5.0.0",
"zero-fill": "^2.2.3" "zero-fill": "^2.2.3"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.6.3", "@babel/core": "^7.8.3",
"@babel/preset-env": "^7.6.3", "@babel/preset-env": "^7.8.3",
"@babel/register": "^7.6.2", "@babel/register": "^7.8.3",
"autosize": "^4.0.2", "autosize": "^4.0.2",
"babel-loader": "^8.0.6", "babel-loader": "^8.0.6",
"binary-loader": "0.0.1", "binary-loader": "0.0.1",
"del": "^5.1.0", "del": "^5.1.0",
"eslint": "^6.5.1", "eslint": "^6.8.0",
"eslint-plugin-standard": "^4.0.1", "eslint-plugin-standard": "^4.0.1",
"exports-loader": "^0.7.0", "exports-loader": "^0.7.0",
"fancy-log": "^1.3.3", "fancy-log": "^1.3.3",
@ -67,19 +67,19 @@
"gulp-chmod": "^3.0.0", "gulp-chmod": "^3.0.0",
"gulp-filter": "^6.0.0", "gulp-filter": "^6.0.0",
"gulp-header": "^2.0.9", "gulp-header": "^2.0.9",
"gulp-json-editor": "^2.5.3", "gulp-json-editor": "^2.5.4",
"gulp-rename": "^1.4.0", "gulp-rename": "^2.0.0",
"gulp-standard": "^14.0.0", "gulp-standard": "^14.0.0",
"gulp-watch": "^5.0.1", "gulp-watch": "^5.0.1",
"gulp-zip": "^5.0.1", "gulp-zip": "^5.0.1",
"plugin-error": "^1.0.1", "plugin-error": "^1.0.1",
"raw-loader": "^3.1.0", "raw-loader": "^4.0.0",
"regenerator-runtime": "^0.13.3", "regenerator-runtime": "^0.13.3",
"removeNPMAbsolutePaths": "^2.0.0", "removeNPMAbsolutePaths": "^2.0.0",
"standard": "^14.3.1", "standard": "^14.3.1",
"stylus": "^0.54.7", "stylus": "^0.54.7",
"stylus-loader": "^3.0.2", "stylus-loader": "^3.0.2",
"webpack": "^4.41.0", "webpack": "^4.41.5",
"webpack-node-externals": "^1.7.2" "webpack-node-externals": "^1.7.2"
}, },
"standard": { "standard": {

View file

@ -6,7 +6,7 @@ import { XmlEntities } from 'html-entities'
import sanitize from 'sanitize-filename' import sanitize from 'sanitize-filename'
import { URL } from 'url' import { URL } from 'url'
import isNode from 'detect-node' import isNode from 'detect-node'
import fileType from 'file-type' import FileType from 'file-type'
import isSvg from 'is-svg' import isSvg from 'is-svg'
import sizeOf from 'image-size' import sizeOf from 'image-size'
import EventEmitter from 'events' import EventEmitter from 'events'
@ -324,7 +324,7 @@ class FimFic2Epub extends EventEmitter {
fetchRemote(url, 'arraybuffer').then(async (data) => { fetchRemote(url, 'arraybuffer').then(async (data) => {
r.dest = null r.dest = null
let info = fileType(isNode ? data : new Uint8Array(data)) let info = await FileType.fromBuffer(isNode ? data : new Uint8Array(data))
if (!info || info.mime === 'application/xml') { if (!info || info.mime === 'application/xml') {
// file-type doesn't support SVG, extra check: // file-type doesn't support SVG, extra check:
if (isSvg(Buffer.from(data).toString('utf8'))) { if (isSvg(Buffer.from(data).toString('utf8'))) {
@ -346,7 +346,7 @@ class FimFic2Epub extends EventEmitter {
checksums.set(checksum, url) checksums.set(checksum, url)
if (info.mime === 'image/webp') { if (info.mime === 'image/webp') {
data = await utils.webp2png(isNode ? data : new Uint8Array(data)) data = await utils.webp2png(isNode ? data : new Uint8Array(data))
info = fileType(data) info = await FileType.fromBuffer(data)
} }
const type = info.mime const type = info.mime
r.type = type r.type = type
@ -593,9 +593,9 @@ class FimFic2Epub extends EventEmitter {
this.filename = FimFic2Epub.getFilename(this.storyInfo) this.filename = FimFic2Epub.getFilename(this.storyInfo)
} }
setCoverImage (buffer) { async setCoverImage (buffer) {
buffer = isNode ? buffer : Buffer.from(new Uint8Array(buffer)) buffer = isNode ? buffer : Buffer.from(new Uint8Array(buffer))
const info = fileType(buffer) const info = await FileType.fromBuffer(buffer)
if (!info || !info.mime.startsWith('image/')) { if (!info || !info.mime.startsWith('image/')) {
throw new Error('Invalid image') throw new Error('Invalid image')
} }
@ -603,6 +603,7 @@ class FimFic2Epub extends EventEmitter {
this.coverFilename = 'Images/cover.' + info.ext this.coverFilename = 'Images/cover.' + info.ext
this.coverType = info.mime this.coverType = info.mime
this.coverImageDimensions = sizeOf(Buffer.from(buffer)) this.coverImageDimensions = sizeOf(Buffer.from(buffer))
return this.coverImage
} }
// Internal/private methods // Internal/private methods
@ -737,16 +738,14 @@ class FimFic2Epub extends EventEmitter {
ctx.fillText(author, canvas.width / 2, canvas.height * 0.9) ctx.fillText(author, canvas.width / 2, canvas.height * 0.9)
this.setCoverImage(Buffer.from(canvas.toDataURL('image/jpeg').split(',')[1], 'base64')) return this.setCoverImage(Buffer.from(canvas.toDataURL('image/jpeg').split(',')[1], 'base64'))
return Promise.resolve(this.coverImage)
} }
this.progress(0, 0, 'Fetching cover image...') this.progress(0, 0, 'Fetching cover image...')
this.pcache.coverImage = fetchRemote(url, 'arraybuffer').then((data) => { this.pcache.coverImage = fetchRemote(url, 'arraybuffer').then(async (data) => {
data = isNode ? data : new Uint8Array(data) data = isNode ? data : new Uint8Array(data)
const info = fileType(data) const info = await FileType.fromBuffer(data)
if (info) { if (info) {
const type = info.mime const type = info.mime
const isImage = type.startsWith('image/') const isImage = type.startsWith('image/')

View file

@ -329,9 +329,8 @@ function createEpub (model) {
} else if (model.coverFile()) { } else if (model.coverFile()) {
chain = chain chain = chain
.then(() => blobToArrayBuffer(model.coverFile())) .then(() => blobToArrayBuffer(model.coverFile()))
.then((buf) => { .then((buf) => ffc.setCoverImage(buf))
ffc.setCoverImage(buf) .catch((err) => console.error(err))
}).catch((err) => console.error(err))
} }
ffc.setTitle(model.title()) ffc.setTitle(model.title())

View file

@ -340,9 +340,9 @@ figure.youtube {
} }
svg.chapterbars { svg.chapterbars {
width: 100%; height: 6em;
display: block; display: block;
margin: 1em 0; margin: 1em auto;
page-break-inside: avoid; page-break-inside: avoid;
break-inside: avoid; break-inside: avoid;
-webkit-column-break-inside: avoid; -webkit-column-break-inside: avoid;

View file

@ -3,12 +3,12 @@ import isNode from 'detect-node'
import { Font } from 'fonteditor-core' import { Font } from 'fonteditor-core'
import fs from 'fs' import fs from 'fs'
import fetch from './fetch' import fetch from './fetch'
import fileType from 'file-type' import FileType from 'file-type'
async function subsetFont (fontPath, glyphs, options = {}) { async function subsetFont (fontPath, glyphs, options = {}) {
let data let data
const fontdata = Buffer.from(fontPath, 'binary') const fontdata = Buffer.from(fontPath, 'binary')
const type = fileType(fontdata) const type = await FileType.fromBuffer(fontdata)
if (type && type.mime === 'font/ttf') { if (type && type.mime === 'font/ttf') {
data = fontdata.buffer data = fontdata.buffer
} else { } else {