From 1ae51b18f82ba1b169b13cbb7f3b734c15c16bf6 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:54 +0200 Subject: [PATCH] Added preview property. Removed debugging intercepts. Logging post permalink on failed info fetch. --- src/app.js | 2 +- src/curate/posts.js | 3 +-- src/fetch/content.js | 4 ---- src/fetch/info.js | 8 +++++--- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/app.js b/src/app.js index 68e96f5..3886d5e 100644 --- a/src/app.js +++ b/src/app.js @@ -44,7 +44,7 @@ Promise.resolve().then(() => { }).then(posts => { return curatePosts(posts, args.ignore).slice(0, args.limit); }).then(posts => { - return attachContentInfo(posts).then(info => posts); + return attachContentInfo(posts); }).then(posts => { return fetchContent(posts); }).catch(error => { diff --git a/src/curate/posts.js b/src/curate/posts.js index fd0edbb..13b2136 100644 --- a/src/curate/posts.js +++ b/src/curate/posts.js @@ -6,8 +6,6 @@ const dissectLink = require('../dissectLink.js'); function curatePosts(posts, ignore) { const processed = new Set(); - console.log(ignore); - return posts.reduce((acc, post, index) => { const host = dissectLink(post.url); const ignoring = ignore ? ignore.find(prop => { @@ -40,6 +38,7 @@ function curatePosts(posts, ignore) { url: post.url, datetime: new Date(post.created_utc * 1000), subreddit: post.subreddit.display_name, + preview: post.preview ? post.preview.images.map(image => image.source) : null, host }); }, []); diff --git a/src/fetch/content.js b/src/fetch/content.js index 9237d38..ccfbfb5 100644 --- a/src/fetch/content.js +++ b/src/fetch/content.js @@ -21,10 +21,6 @@ module.exports = function(posts) { return ep.open(); }).then(() => { return Promise.all(posts.map(post => { - if(!post.content) { - return console.log('SLIPPED THROUGH!', post); - } - return Promise.all(post.content.items.map((item, index) => { item.index = index; diff --git a/src/fetch/info.js b/src/fetch/info.js index df83834..0019f00 100644 --- a/src/fetch/info.js +++ b/src/fetch/info.js @@ -10,16 +10,18 @@ function attachContentInfo(posts) { return post; }).catch(error => { - console.log('\x1b[31m%s\x1b[0m', error); + console.log('\x1b[31m%s\x1b[0m', `${error} (${post.permalink})`); - return null + return null; })); } else { console.log('\x1b[33m%s\x1b[0m', `Ignoring unsupported content '${post.id} - ${post.title} - ${post.url}`); } return acc; - }, [])).then(posts => posts.filter(post => post)); + }, [])).then(posts => posts.filter(post => { + return post; + })); }; module.exports = attachContentInfo;