From fa1ba7ac67c9392281ac4efd5b5de4c922dd3766 Mon Sep 17 00:00:00 2001 From: daniel-j Date: Mon, 7 Sep 2020 17:08:49 +0200 Subject: [PATCH] restore fetchRemote to fix CORS errors, use Author - Title as default filename --- README.md | 2 +- package.json | 2 +- src/FimFic2Epub.js | 7 ++++--- src/fetchRemote.js | 5 ++++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a02fd5b..452aabc 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ You can then run the tool it like this: `$ fimfic2epub []` -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] [filename] diff --git a/package.json b/package.json index a0b179a..af3b040 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/FimFic2Epub.js b/src/FimFic2Epub.js index f392e13..fe97271 100644 --- a/src/FimFic2Epub.js +++ b/src/FimFic2Epub.js @@ -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) { diff --git a/src/fetchRemote.js b/src/fetchRemote.js index 91781b3..65e6911 100644 --- a/src/fetchRemote.js +++ b/src/fetchRemote.js @@ -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) => {