Added preview property. Removed debugging intercepts. Logging post permalink on failed info fetch.

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:54 +02:00
parent f0e312f2b1
commit 1ae51b18f8
4 changed files with 7 additions and 10 deletions

View File

@ -44,7 +44,7 @@ Promise.resolve().then(() => {
}).then(posts => { }).then(posts => {
return curatePosts(posts, args.ignore).slice(0, args.limit); return curatePosts(posts, args.ignore).slice(0, args.limit);
}).then(posts => { }).then(posts => {
return attachContentInfo(posts).then(info => posts); return attachContentInfo(posts);
}).then(posts => { }).then(posts => {
return fetchContent(posts); return fetchContent(posts);
}).catch(error => { }).catch(error => {

View File

@ -6,8 +6,6 @@ const dissectLink = require('../dissectLink.js');
function curatePosts(posts, ignore) { function curatePosts(posts, ignore) {
const processed = new Set(); const processed = new Set();
console.log(ignore);
return posts.reduce((acc, post, index) => { return posts.reduce((acc, post, index) => {
const host = dissectLink(post.url); const host = dissectLink(post.url);
const ignoring = ignore ? ignore.find(prop => { const ignoring = ignore ? ignore.find(prop => {
@ -40,6 +38,7 @@ function curatePosts(posts, ignore) {
url: post.url, url: post.url,
datetime: new Date(post.created_utc * 1000), datetime: new Date(post.created_utc * 1000),
subreddit: post.subreddit.display_name, subreddit: post.subreddit.display_name,
preview: post.preview ? post.preview.images.map(image => image.source) : null,
host host
}); });
}, []); }, []);

View File

@ -21,10 +21,6 @@ module.exports = function(posts) {
return ep.open(); return ep.open();
}).then(() => { }).then(() => {
return Promise.all(posts.map(post => { return Promise.all(posts.map(post => {
if(!post.content) {
return console.log('SLIPPED THROUGH!', post);
}
return Promise.all(post.content.items.map((item, index) => { return Promise.all(post.content.items.map((item, index) => {
item.index = index; item.index = index;

View File

@ -10,16 +10,18 @@ function attachContentInfo(posts) {
return post; return post;
}).catch(error => { }).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 { } else {
console.log('\x1b[33m%s\x1b[0m', `Ignoring unsupported content '${post.id} - ${post.title} - ${post.url}`); console.log('\x1b[33m%s\x1b[0m', `Ignoring unsupported content '${post.id} - ${post.title} - ${post.url}`);
} }
return acc; return acc;
}, [])).then(posts => posts.filter(post => post)); }, [])).then(posts => posts.filter(post => {
return post;
}));
}; };
module.exports = attachContentInfo; module.exports = attachContentInfo;