restore fetchRemote to fix CORS errors, use Author - Title as default filename

This commit is contained in:
daniel-j 2020-09-07 17:08:49 +02:00
parent ecf6e43cfd
commit fa1ba7ac67
4 changed files with 10 additions and 6 deletions

View file

@ -44,7 +44,7 @@ You can then run the tool it like this:
`$ fimfic2epub <story id/url> [<optional filename>]`
By default the EPUB will be saved in the current working directory with the filename `Title by Author.epub`. Run `fimfic2epub -h` to see a list of all flags.
By default the EPUB will be saved in the current working directory with the filename `Author - Title.epub`. Run `fimfic2epub -h` to see a list of all flags.
```
Usage: fimfic2epub [options] <story> [filename]

View file

@ -1,6 +1,6 @@
{
"name": "fimfic2epub",
"version": "1.7.48",
"version": "1.7.49",
"description": "Tool to generate improved EPUB ebooks from Fimfiction stories",
"author": "djazz",
"license": "MIT",

View file

@ -14,6 +14,7 @@ import { buf as crc32 } from 'crc-32'
import { cleanMarkup } from './cleanMarkup'
import fetch from './fetch'
import fetchRemote from './fetchRemote'
import * as template from './templates'
import { styleCss, coverstyleCss, titlestyleCss, iconsCss, navstyleCss, paragraphsCss } from './styles'
import * as utils from './utils'
@ -42,7 +43,7 @@ class FimFic2Epub extends EventEmitter {
}
static getFilename (storyInfo) {
return sanitize(storyInfo.title + ' by ' + storyInfo.author.name + '.epub')
return sanitize(storyInfo.author.name + ' - ' + storyInfo.title + '.epub')
}
static fetchStoryInfo (storyId, raw = false) {
@ -325,7 +326,7 @@ class FimFic2Epub extends EventEmitter {
console.log('Remote file URL: ' + url)
fetch(url, 'arraybuffer').then(async (data) => {
fetchRemote(url, 'arraybuffer').then(async (data) => {
r.dest = null
let info = await FileType.fromBuffer(isNode ? data : new Uint8Array(data))
if (!info || info.mime === 'application/xml') {
@ -746,7 +747,7 @@ class FimFic2Epub extends EventEmitter {
this.progress(0, 0, 'Fetching cover image...')
this.pcache.coverImage = fetch(url, 'arraybuffer').then(async (data) => {
this.pcache.coverImage = fetchRemote(url, 'arraybuffer').then(async (data) => {
data = isNode ? data : new Uint8Array(data)
const info = await FileType.fromBuffer(data)
if (info) {

View file

@ -61,7 +61,10 @@ export default function fetchRemote (url, responseType) {
if (url.startsWith('//')) {
url = 'https:' + url
}
if (!isNode && document.location.protocol === 'https:' && url.startsWith('http:')) {
if (!isNode && document.location.protocol === 'https:') {
if (url.startsWith('/')) {
url = window.location.origin + url
}
return fetchBackground(url, responseType)
}
return fetch(url, responseType).then((data) => {