33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const util = require('util');
|
|
const config = require('config');
|
|
const Promise = require('bluebird');
|
|
const methods = require('../methods/methods.js');
|
|
|
|
const attachContentInfo = users => {
|
|
return Promise.reduce(Object.values(users), async (accUsers, user) => ({...accUsers, [user.name]: {...user, posts: await Promise.reduce(user.posts, async (accPosts, post) => {
|
|
if(!post.host || !methods[post.host.method]) {
|
|
console.log('\x1b[33m%s\x1b[0m', `Ignoring unsupported content '${post.url}' (${post.permalink})`);
|
|
|
|
return accPosts;
|
|
}
|
|
|
|
try {
|
|
return [...accPosts, {...post, content: await methods[post.host.method](post)}];
|
|
} catch(error) {
|
|
console.log('\x1b[31m%s\x1b[0m', `${error} (${post.permalink})`);
|
|
|
|
if(config.fetch.archives.preview && post.preview) {
|
|
console.log(`Found preview images for unavailable source '${post.url}' (${post.permalink})`);
|
|
|
|
return [...accPosts, {...post, previewFallback: true, content: await methods.redditPreview(post)}];
|
|
}
|
|
|
|
return accPosts;
|
|
}
|
|
}, [])}}), {});
|
|
};
|
|
|
|
module.exports = attachContentInfo;
|