From 5142cfa2b91ee6e1dab7963dcafb7fc73605a3ab Mon Sep 17 00:00:00 2001 From: xangelo Date: Fri, 26 Jan 2024 22:49:57 -0500 Subject: [PATCH] clean up bugs around feed checking --- src/server.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/server.ts b/src/server.ts index 579f3ee..707c0a0 100644 --- a/src/server.ts +++ b/src/server.ts @@ -26,6 +26,8 @@ function contentExtractor(feed: FeedSchema, item): string { break; } + str = str.replace(/<[^>]+>/g, ''); + return str; } @@ -35,11 +37,11 @@ async function queryFeeds() { const feedsToQuery = completeFeedList.filter(feed => { // only update every 5 minutes - //return Date.now() > (feed.updated_at + 1000 * 60 * 5); - return true; + return Date.now() > (feed.updated_at + (1000 * 60 * 5)); }); console.log(`Querying ${feedsToQuery.length} feeds`); + const now = Date.now(); for(let feed of feedsToQuery) { console.log(`Querying ${feed.title}(${feed.url})`); @@ -48,14 +50,14 @@ async function queryFeeds() { const items: FeedEntrySchema[] = data.items.map(item => { return { - id: item.guid, + id: item.guid || item.id, title: item.title, link: item.link, feed_id: feed.id, pub_date: Math.floor(new Date(item.pubDate).getTime()/1000), - author: item.creator, - created_at: Math.floor(Date.now()/1000), - updated_at: Math.floor(Date.now()/1000), + author: item.creator || item.author, + created_at: Math.floor(now/1000), + updated_at: Math.floor(now/1000), meta: { comment_link: item.comments, snippet: contentExtractor(feed, item) @@ -70,7 +72,7 @@ async function queryFeeds() { } await db('feeds').update({ - updated_at: new Date() + updated_at: Math.floor(Date.now()/1000) }).where({ id: feed.id }); @@ -164,7 +166,7 @@ app.post('/feeds', async (req, res) => { title: req.body.title, favicon: req.body.favicon, created_at: now, - updated_at: now + updated_at: 0 }; const rows = await db('feeds').insert(feed).onConflict().ignore().returning('*'); -- 2.25.1