log to file
This commit is contained in:
+23
-7
@@ -25,12 +25,17 @@ function cleanPath(pathToClean) {
|
|||||||
return cleanPath;
|
return cleanPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function log(text) {
|
||||||
|
let d = new Date();
|
||||||
|
let datetime = `${d.getFullYear()}.${(d.getMonth() + 1)}.${d.getDate()}_${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;
|
||||||
|
fs.appendFile(cleanPath('./WNtoEmail.log'), `${datetime} ${text}\n`);
|
||||||
|
}
|
||||||
|
|
||||||
async function mkDir(dirPath) {
|
async function mkDir(dirPath) {
|
||||||
try {
|
try {
|
||||||
await fs.access(cleanPath(dirPath));
|
await fs.access(cleanPath(dirPath));
|
||||||
}
|
}
|
||||||
catch (err)
|
catch (err) {
|
||||||
{
|
|
||||||
await fs.mkdir(dirPath, { recursive: true });
|
await fs.mkdir(dirPath, { recursive: true });
|
||||||
}
|
}
|
||||||
await fs.access(cleanPath(dirPath));
|
await fs.access(cleanPath(dirPath));
|
||||||
@@ -123,16 +128,21 @@ async function convertEbook(dir, file, params = { "cover": false, "authors": fal
|
|||||||
convertParams += params['title'] ? ` --title "${params['title']}"` : '';
|
convertParams += params['title'] ? ` --title "${params['title']}"` : '';
|
||||||
|
|
||||||
console.log(`Converting volume: ${file1Path}`);
|
console.log(`Converting volume: ${file1Path}`);
|
||||||
|
log(`Converting volume: ${file1Path}`);
|
||||||
|
|
||||||
exec(`${config['converterPath']} "${file1Path}" "${file2Path}"${convertParams}`, (error, stdout, stderr) => {
|
exec(`${config['converterPath']} "${file1Path}" "${file2Path}"${convertParams}`, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(`error: ${error.message}`);
|
console.log(`error: ${error.message}`);
|
||||||
|
log(`error: ${error.message}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
console.log(`stderr: ${stderr}`);
|
console.log(`stderr: ${stderr}`);
|
||||||
|
log(`stderr: ${stderr}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(`stdout: ${stdout}`);
|
console.log(`stdout: ${stdout}`);
|
||||||
|
log(`stdout: ${stdout}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,18 +161,20 @@ function sendEbook(subject, ebookAttachments) {
|
|||||||
let message = {
|
let message = {
|
||||||
from: config['emailFromAddress'],
|
from: config['emailFromAddress'],
|
||||||
to: config['emailToAddress'],
|
to: config['emailToAddress'],
|
||||||
subject: subject + ' part ' + i,
|
subject: subject + ' part ' + (i + 1),
|
||||||
text: subject + ' part ' + i,
|
text: subject + ' part ' + (i + 1),
|
||||||
attachments: splicedAttachments[i]
|
attachments: splicedAttachments[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
transporter.sendMail(message, (err) => {
|
transporter.sendMail(message, (err) => {
|
||||||
if (err)
|
if (err)
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
log(err);
|
||||||
else
|
|
||||||
console.log(`Sent volume ${ebook}`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(`Sent volumes:`);
|
||||||
|
log(`Sent volumes:`);
|
||||||
|
splicedAttachments[i].forEach(elem => console.log(elem['filename']))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -309,6 +321,7 @@ async function main() {
|
|||||||
|
|
||||||
let chapter = await fetchChapter(novelInfo[3], 'NF');
|
let chapter = await fetchChapter(novelInfo[3], 'NF');
|
||||||
console.log('Download chapter ' + chapters.length + ' ' + novelInfo[3]);
|
console.log('Download chapter ' + chapters.length + ' ' + novelInfo[3]);
|
||||||
|
log('Download chapter ' + chapters.length + ' ' + novelInfo[3]);
|
||||||
chapters.push(chapter);
|
chapters.push(chapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,6 +334,7 @@ async function main() {
|
|||||||
novel['lastChapterURL'] = nextChapterURL;
|
novel['lastChapterURL'] = nextChapterURL;
|
||||||
let chapter = await fetchChapter(nextChapterURL, 'NF');
|
let chapter = await fetchChapter(nextChapterURL, 'NF');
|
||||||
console.log('Download chapter ' + chapters.length + ' ' + nextChapterURL);
|
console.log('Download chapter ' + chapters.length + ' ' + nextChapterURL);
|
||||||
|
log('Download chapter ' + chapters.length + ' ' + nextChapterURL);
|
||||||
chapters.push(chapter);
|
chapters.push(chapter);
|
||||||
nextChapterURL = chapter[1];
|
nextChapterURL = chapter[1];
|
||||||
}
|
}
|
||||||
@@ -349,6 +363,7 @@ async function main() {
|
|||||||
|
|
||||||
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
||||||
console.log(`Saved volume: ${novelFileName}`);
|
console.log(`Saved volume: ${novelFileName}`);
|
||||||
|
log(`Saved volume: ${novelFileName}`);
|
||||||
|
|
||||||
await convertEbook(novelDir, novelFileName, {
|
await convertEbook(novelDir, novelFileName, {
|
||||||
cover: novel['coverURL'],
|
cover: novel['coverURL'],
|
||||||
@@ -384,6 +399,7 @@ async function main() {
|
|||||||
|
|
||||||
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
||||||
console.log(`Saved volume: ${novelFileName}`);
|
console.log(`Saved volume: ${novelFileName}`);
|
||||||
|
log(`Saved volume: ${novelFileName}`);
|
||||||
|
|
||||||
await convertEbook(novelDir, novelFileName, {
|
await convertEbook(novelDir, novelFileName, {
|
||||||
cover: novel['coverURL'],
|
cover: novel['coverURL'],
|
||||||
|
|||||||
Reference in New Issue
Block a user