You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[safari-downloader] downloaded chapter files...
[safari-downloader] downloaded stylesheet files...
[safari-downloader] an error occurred while trying to download all the image assets (err: HTTPError: Response code 500 (Internal Server Error))
I've noticed that image downloader does not includes authroized header.
I try to use Safari client and the downloads is successful.
diff --git a/lib/cli/index.js b/lib/cli/index.js
index f223f30..e568811 100644
--- a/lib/cli/index.js+++ b/lib/cli/index.js@@ -105,7 +105,7 @@ function start() {
var safariClient = new Safari(program.debug);
safariClient.fetchBookById(program.bookid, username, password, cookies, program.weblogin).then( (bookJSON) => {
// console.log(bookJSON);
- var ebook = new EbookWriter(bookJSON);+ var ebook = new EbookWriter(safariClient, bookJSON);
return ebook.save(program.output);
}).then( () => {
// ## finished saving
diff --git a/lib/ebook-writer/index.js b/lib/ebook-writer/index.js
index 3e66341..7ee8052 100644
--- a/lib/ebook-writer/index.js+++ b/lib/ebook-writer/index.js@@ -15,12 +15,13 @@ const mime = require('mime');
* ## eBook Writer
* sets up the ebook writer with its base settings
*
+* @param {Safari} safariClient - Safari instance
* @param {Object} options - the options for the ebook (e.g. content, title, name, etc.)
*
* @return {Object} ebook - returns a ebook object
*/
-const Ebook = function Ebook(options) {-+const Ebook = function Ebook(safariClient, options) {+ this.safariClient = safariClient;
// ## prepare base settings
this.tempPath = "books";
this.options = options || {};
@@ -323,7 +324,9 @@ function _writeCSS(that) {
* @return {Promise} success - returns whether the creation was successful or not
*/
function _downloadCoverImage(that) {
- return download(that.options.cover).then( (data) => {+ return that.safariClient.fetchResource(that.options.cover, {+ binary: true+ }).then((data) => {
debug(`cover image successfully fetched`);
// ## writing the file to the images directory
// ## using writeFileSync on purpose; might be using async in the future
@@ -388,14 +391,16 @@ function _prepareImages(that) {
* ## Download images
* downloads all the image assets
*
-* @param {String} that - the ebook object+* @param {Ebook} that - the ebook object
*
* @return {Promise} success - returns whether the creation was successful or not
*/
function _downloadImages(that) {
if(!that.options.imagesToFetch) return Promise.reject("there are no images to be fetched yet; prepare first");
return Promise.all(that.options.imagesToFetch.map( (image) => {
- return download(image.baseUrl + image.file).then( (data) => {+ return that.safariClient.fetchResource(image.baseUrl + image.file, {+ binary: true+ }).then((data) => {
// ## the image was successfully downloded, writing to image path
debug(`${image.file} successfully fetched`);
// ## writing the file to the images directory
@@ -403,6 +408,9 @@ function _downloadImages(that) {
let path = that.tempBookPath + "/OEBPS/images/" + image.path;
fs.writeFileSync(path, data);
return Promise.resolve();
+ }).catch(error => {+ debug(`${imagqe.file} failure fetched`);+ return Promise.reject(error);
});
})).then( () => {
// ## the downloading was successfully finished
diff --git a/lib/safari/index.js b/lib/safari/index.js
index 7211eaa..b65e128 100644
--- a/lib/safari/index.js+++ b/lib/safari/index.js@@ -126,18 +126,19 @@ Safari.prototype.fetchResource = function fetchResource(url, options) {
debug(`fetchResource called with URL: ${url}`);
if(!url || !this.accessToken && !this.cookieString) return Promise.reject("url was not specified or user has not been authorized yet");
// ## prepare options for resource request
- var uri = `${this.baseUrl}/${url}`;+ var uri = /^https?:/.test(url) ? url : `${this.baseUrl}/${url}`;
var json = true;
var headers = {}
if(this.access_token) headers["authorization"] = `Bearer ${this.accessToken}`
if(this.cookieString) headers["cookie"] = `${this.cookieString}`
- if(options && options.json == false) json = false;+ if(options && (options.json === false || options.binary === true)) json = false;
if(options && options.uri) uri = options.uri;
let settings = {
method: 'GET',
headers: headers,
uri: uri,
- json: json+ json: json,+ encoding: options && options.binary ? null : "utf-8"
};
// ## make request
return request(settings).then( (body) => {
However, I just use curl and it is successs.
Maybe, download module is something wrong,
I've tested on https://learning.oreilly.com/library/view/distributed-tracing-in/9781492056621/ and get following erros:
I've noticed that image downloader does not includes authroized header.
I try to use
Safari
client and the downloads is successful.However, I just use
curl
and it is successs.Maybe, download module is something wrong,
The text was updated successfully, but these errors were encountered: