From 3cc2c67949bd59a00b4d07aa1e0e5a1d968de9c7 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 20 Feb 2020 10:04:34 +0000 Subject: [PATCH] Make it work on nodejs 13 --- README.md | 18 ++++++++++-------- main.js | 16 +++++++++++----- package.json | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d47cd4e..bd33e7c 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,24 @@ This is a node script extracting E-Books from Amazon Kindle Cloud Reader. Useful e.g. for being able to read on devices where the Cloud Reader doesn't work and for having a copy in an open format. Works with Chrome/Chromium. Other browsers use different formats for the WebSQL file where the E-Books are stored for offline use. -Code is from this gists: +Antecedents: - * 1: https://gist.github.com/yangchenyun/a1c123935d82f5e25d57 - * 2: https://gist.github.com/moodule/84140e557065ac3d73f669f120429ae1 +1. https://gist.github.com/yangchenyun/a1c123935d82f5e25d57 +2. https://gist.github.com/moodule/84140e557065ac3d73f669f120429ae1 +3. https://github.com/d10r/kindle-fetch -I have just added minor usability improvements (e.g. cmdline switch for input file selection) and a package.json file. +`d10r` added minor usability improvements (e.g. cmdline switch for input file selection) and a package.json file. + +I have just updated it to cope with newer versions of Node. ## Usage -This was successfully tested with nodejs v6 and v8 (will print ugly warnings with v8). -Doesn't work for me with nodejs v10 (and reportedly also not with v11). +This was successfully tested with Node v13. -
+```
 npm install
 ./main.js --help
-
+``` This generates HTML files with the book content in the directory you're in. diff --git a/main.js b/main.js index b2699d4..ba904eb 100755 --- a/main.js +++ b/main.js @@ -289,8 +289,10 @@ db.all("select metadata from 'bookinfo'", function(err, rows) { //var HtmlFile = path.join(os.tmpdir(), title.replace(/\s+/g, '-') + '.html'); var HtmlFile = title.replace(/\s+/g, '-') + '.html'; - fs.writeFile(HtmlFile, HtmlHeader); - console.log("created the file with HTML headers."); + fs.writeFile(HtmlFile, HtmlHeader, (err) => { + if (err) throw err; + console.log("created the file with HTML headers."); + }); db.all("select id, piece, other from 'fragments' where asin='" + asin + "' order by id", function(err, rows) { rows.forEach(function (row) { @@ -309,11 +311,15 @@ db.all("select metadata from 'bookinfo'", function(err, rows) { 'dataUrl="' + image + '"', 'src="' + imageDataMap[image] + '"'); } - fs.appendFile(HtmlFile, uncompressedFragmentData); + fs.appendFile(HtmlFile, uncompressedFragmentData, (err) => { + if (err) throw err; + }); }); }); - fs.appendFile(HtmlFile, ''); - console.log("created the file at: " + HtmlFile); + fs.appendFile(HtmlFile, '', (err) =>{ + if (err) throw err; + console.log("created the file at: " + HtmlFile); + }); }); }); diff --git a/package.json b/package.json index 0d39fd7..a0b9047 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,6 @@ "main": "main.js", "dependencies": { "osenv": "^0.1.4", - "sqlite3": "^3.1.8" + "sqlite3": "^4.1.1" } }