Adding nodelogging and unescaping subject for mails
This commit is contained in:
parent
9a0a1da08b
commit
27ed0f4c3b
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
lib/
|
lib/
|
||||||
node_modules/
|
node_modules/
|
||||||
db.json
|
db.json
|
||||||
.env
|
.env
|
||||||
|
logs/
|
@ -13,6 +13,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/dotenv": "^4.0.3",
|
"@types/dotenv": "^4.0.3",
|
||||||
|
"@types/html-entities": "^1.2.16",
|
||||||
"@types/lowdb": "^1.0.5",
|
"@types/lowdb": "^1.0.5",
|
||||||
"@types/node": "^10.7.0",
|
"@types/node": "^10.7.0",
|
||||||
"@types/node-fetch": "^2.1.2",
|
"@types/node-fetch": "^2.1.2",
|
||||||
@ -21,11 +22,13 @@
|
|||||||
"typescript": "^3.0.1"
|
"typescript": "^3.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@hibas123/nodelogging": "^1.3.12",
|
||||||
"dotenv": "^6.0.0",
|
"dotenv": "^6.0.0",
|
||||||
|
"html-entities": "^1.2.1",
|
||||||
"lowdb": "^1.0.0",
|
"lowdb": "^1.0.0",
|
||||||
"node-fetch": "^2.2.0",
|
"node-fetch": "^2.2.0",
|
||||||
"nodemailer": "^4.6.7",
|
"nodemailer": "^4.6.7",
|
||||||
"rss-parser": "^3.4.2",
|
"rss-parser": "^3.4.2",
|
||||||
"ssl-root-cas": "^1.2.5"
|
"ssl-root-cas": "^1.2.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
19
src/index.ts
19
src/index.ts
@ -2,6 +2,8 @@ require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create(
|
|||||||
require('ssl-root-cas').inject();
|
require('ssl-root-cas').inject();
|
||||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||||
|
|
||||||
|
import Logging from "@hibas123/nodelogging";
|
||||||
|
|
||||||
import * as dotenv from "dotenv";
|
import * as dotenv from "dotenv";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
import rss from "rss-parser";
|
import rss from "rss-parser";
|
||||||
@ -53,33 +55,34 @@ function calculateHash(item: FeedItem) {
|
|||||||
async function check() {
|
async function check() {
|
||||||
try {
|
try {
|
||||||
let data = await fetch(process.env.FEED).then(res => res.text());
|
let data = await fetch(process.env.FEED).then(res => res.text());
|
||||||
console.log("Received Data");
|
Logging.log("Received Data");
|
||||||
let feed: Feed = await parser.parseString(data).catch(console.error);
|
let feed: Feed = await parser.parseString(data).catch(err => Logging.error(err));
|
||||||
//Check for new entries
|
//Check for new entries
|
||||||
let items = feed.items.filter(item => {
|
let items = feed.items.filter(item => {
|
||||||
return db.get(calculateHash(item)).value() !== true;
|
return db.get(calculateHash(item)).value() !== true;
|
||||||
})
|
})
|
||||||
for (let item of items) {
|
for (let item of items) {
|
||||||
await sendFeed(feed, item).catch(console.error)
|
await sendFeed(feed, item).catch(err => Logging.error(err))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
Logging.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import {AllHtmlEntities} from "html-entities";
|
||||||
|
const entities = new AllHtmlEntities();
|
||||||
async function sendFeed(feed: Feed, item: FeedItem) {
|
async function sendFeed(feed: Feed, item: FeedItem) {
|
||||||
console.log("Sending Mail!")
|
Logging.log("Sending Mail!")
|
||||||
let mailOptions = {
|
let mailOptions = {
|
||||||
from: process.env.MAIL_SENDER,
|
from: process.env.MAIL_SENDER,
|
||||||
to: process.env.MAIL_RECEIVER,
|
to: process.env.MAIL_RECEIVER,
|
||||||
subject: '[OSPLUS_UPDATE] ' + unescape(item.title),
|
subject: '[OSPLUS_UPDATE] ' + entities.decode(item.title),
|
||||||
text: item.contentSnippet,
|
text: item.contentSnippet,
|
||||||
html: item.content
|
html: item.content
|
||||||
};
|
};
|
||||||
|
|
||||||
let info = await transporter.sendMail(mailOptions);
|
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();
|
db.set(calculateHash(item), true).write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user