Added support for directly sending epubs
This commit is contained in:
parent
a7b3e3e14b
commit
a0963842a6
28
index.js
28
index.js
@ -17,6 +17,9 @@ const server = http.createServer(async (req, res) => {
|
|||||||
if (website.toString().endsWith(".pdf")) {
|
if (website.toString().endsWith(".pdf")) {
|
||||||
fn = sendPDF;
|
fn = sendPDF;
|
||||||
}
|
}
|
||||||
|
if (website.toString().endsWith(".epub")) {
|
||||||
|
fn = sendEpub;
|
||||||
|
}
|
||||||
|
|
||||||
if (await fn(website)) {
|
if (await fn(website)) {
|
||||||
fs.readFile(__dirname + "/success.html", function (err,data) {
|
fs.readFile(__dirname + "/success.html", function (err,data) {
|
||||||
@ -84,6 +87,25 @@ async function sendPDF(website, tries = 0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendEpub(website, tries = 0) {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(website.toString(), {
|
||||||
|
responseType: 'arraybuffer'
|
||||||
|
})
|
||||||
|
const title = website.toString().substring(website.toString().lastIndexOf("/")+1, website.toString().lastIndexOf("."))
|
||||||
|
await sendToRemarkable(title, Buffer.from(response.data, 'binary'), 'epub');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (ex) {
|
||||||
|
console.log(ex);
|
||||||
|
if (tries < 5) {
|
||||||
|
return await sendEpub(website, ++tries);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function sendPage(website, tries = 0) {
|
async function sendPage(website, tries = 0) {
|
||||||
const browser = await puppeteer.launch({
|
const browser = await puppeteer.launch({
|
||||||
ignoreHTTPSErrors: true,
|
ignoreHTTPSErrors: true,
|
||||||
@ -208,7 +230,7 @@ async function sendPage(website, tries = 0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendToRemarkable(title, myPDF) {
|
async function sendToRemarkable(title, myPDF, fileType = "pdf") {
|
||||||
try {
|
try {
|
||||||
// Refresh token
|
// Refresh token
|
||||||
let response = await axios.post(
|
let response = await axios.post(
|
||||||
@ -257,7 +279,7 @@ async function sendToRemarkable(title, myPDF) {
|
|||||||
let zip = new JSZip();
|
let zip = new JSZip();
|
||||||
zip.file(`${ID}.content`, JSON.stringify({
|
zip.file(`${ID}.content`, JSON.stringify({
|
||||||
extraMetadata: {},
|
extraMetadata: {},
|
||||||
fileType: 'pdf',
|
fileType: fileType,
|
||||||
lastOpenedPage: 0,
|
lastOpenedPage: 0,
|
||||||
lineHeight: -1,
|
lineHeight: -1,
|
||||||
margins: 180,
|
margins: 180,
|
||||||
@ -266,7 +288,7 @@ async function sendToRemarkable(title, myPDF) {
|
|||||||
transform: {},
|
transform: {},
|
||||||
}));
|
}));
|
||||||
zip.file(`${ID}.pagedata`, []);
|
zip.file(`${ID}.pagedata`, []);
|
||||||
zip.file(`${ID}.pdf`, myPDF);
|
zip.file(`${ID}.${fileType}`, myPDF);
|
||||||
const zipContent = await zip.generateAsync({ type: 'nodebuffer' });
|
const zipContent = await zip.generateAsync({ type: 'nodebuffer' });
|
||||||
|
|
||||||
// Upload zip
|
// Upload zip
|
||||||
|
Loading…
Reference in New Issue
Block a user