Fixed bug in RSS engine

This commit is contained in:
Logan Cusano
2023-02-26 05:09:45 -05:00
parent 85b5ed02cf
commit a9bc2383ba
4 changed files with 38 additions and 53 deletions

View File

@@ -70,35 +70,12 @@ exports.deleteSource = function (title, callback) {
});
}
/**
* Adds a new source url to configured storage
* @constructor
* @param {string} category - Category to select Feed by, defaults to all.
*/
exports.getPosts = async (category) => {
postStorage.getAllRecords((err, results) => {
if (category == null || category == undefined || category == "" || category.toLowerCase() == "all") {
if (err) throw err;
if (results.length > 1)
return results;
}
var rssFilteredFeed;
for (const rssFeed of results){
if (rssFeed.category.toLowerCase() == category.toLowerCase()) {
rssFilteredFeed.push(rssFeed);
}
}
return rssFilteredFeed;
});
}
/**
* Update channels with new posts from sources
*/
exports.updateFeeds = async (client) => {
if (!client) throw new Error("Client object not passed");
feedStorage.getAllRecords((err, records) => {
feedStorage.getAllRecords(async (err, records) => {
// Load the posts from each RSS source
for (const source of records) {
log.DEBUG('Record title: ', source.title);
@@ -107,31 +84,35 @@ exports.updateFeeds = async (client) => {
log.DEBUG('Record guild ID: ', source.guild_id);
log.DEBUG('Record channel ID: ', source.channel_id);
parser.parseURL(source.link, (err, parsedFeed) => {
await parser.parseURL(source.link, async (err, parsedFeed) => {
if (err) {
log.ERROR("Parser Error: ", source.link, err);
//return;
}
}
log.DEBUG("Parsed Feed Keys", Object.keys(parsedFeed), parsedFeed?.title);
if (parsedFeed?.items){
for (const post of parsedFeed.items){
if (post.title && post.link && post.content && post.guid && post.pubDate){
postStorage.getRecordBy('post_guid', post.guid, (err, results) => {
for (const post of parsedFeed.items){
log.VERBOSE("Post from feed: ", post);
if (post.title && post.link && post.content && ( post.postId || post.guid || post.id ) && post.pubDate){
post.postId = post.postId ?? post.guid ?? post.id;
postStorage.getRecordBy('post_guid', post.postId, (err, existingRecord) => {
if (err) throw err;
log.DEBUG("Results from asdasdasd: ", results);
if (!results){
log.DEBUG("Existing post record: ", existingRecord);
if (!existingRecord){
const channel = client.channels.cache.get(source.channel_id);
libUtils.sendPost(post, channel, (err, results) =>{
libUtils.sendPost(post, channel, (err, sendResults) =>{
if (err) throw err;
if (results){
log.DEBUG("Saving post to database: ", results, post.title, source.channel_id);
if (sendResults){
log.DEBUG("Saving post to database: ", sendResults, post.title, source.channel_id);
postStorage.savePost(post, (err, results) => {
postStorage.savePost(post, (err, saveResults) => {
if(err) throw err;
if (results) {
log.DEBUG("Saved results: ", results);
if (saveResults) {
log.DEBUG("Saved results: ", saveResults);
}
});
}