Adding nodelogging and unescaping subject for mails

This commit is contained in:
Fabian Stamm 2018-09-27 10:18:56 +02:00
parent 9a0a1da08b
commit 27ed0f4c3b
4 changed files with 346 additions and 10 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
lib/
node_modules/
db.json
.env
.env
logs/

View File

@ -13,6 +13,7 @@
},
"devDependencies": {
"@types/dotenv": "^4.0.3",
"@types/html-entities": "^1.2.16",
"@types/lowdb": "^1.0.5",
"@types/node": "^10.7.0",
"@types/node-fetch": "^2.1.2",
@ -21,11 +22,13 @@
"typescript": "^3.0.1"
},
"dependencies": {
"@hibas123/nodelogging": "^1.3.12",
"dotenv": "^6.0.0",
"html-entities": "^1.2.1",
"lowdb": "^1.0.0",
"node-fetch": "^2.2.0",
"nodemailer": "^4.6.7",
"rss-parser": "^3.4.2",
"ssl-root-cas": "^1.2.5"
}
}
}

View File

@ -2,6 +2,8 @@ require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create(
require('ssl-root-cas').inject();
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
import Logging from "@hibas123/nodelogging";
import * as dotenv from "dotenv";
dotenv.config();
import rss from "rss-parser";
@ -53,33 +55,34 @@ function calculateHash(item: FeedItem) {
async function check() {
try {
let data = await fetch(process.env.FEED).then(res => res.text());
console.log("Received Data");
let feed: Feed = await parser.parseString(data).catch(console.error);
Logging.log("Received Data");
let feed: Feed = await parser.parseString(data).catch(err => Logging.error(err));
//Check for new entries
let items = feed.items.filter(item => {
return db.get(calculateHash(item)).value() !== true;
})
for (let item of items) {
await sendFeed(feed, item).catch(console.error)
await sendFeed(feed, item).catch(err => Logging.error(err))
}
} catch (error) {
console.error(error);
Logging.error(error);
}
}
import {AllHtmlEntities} from "html-entities";
const entities = new AllHtmlEntities();
async function sendFeed(feed: Feed, item: FeedItem) {
console.log("Sending Mail!")
Logging.log("Sending Mail!")
let mailOptions = {
from: process.env.MAIL_SENDER,
to: process.env.MAIL_RECEIVER,
subject: '[OSPLUS_UPDATE] ' + unescape(item.title),
subject: '[OSPLUS_UPDATE] ' + entities.decode(item.title),
text: item.contentSnippet,
html: item.content
};
let info = await transporter.sendMail(mailOptions);
console.log('Message sent: %s', info.messageId);
Logging.log('Message sent: %s', info.messageId);
db.set(calculateHash(item), true).write();
}

329
yarn.lock

File diff suppressed because it is too large Load Diff