30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const util = require('util');
|
|
const config = require('config');
|
|
const methods = require('../methods/methods.js');
|
|
|
|
function attachContentInfo(posts) {
|
|
return Promise.all(posts.reduce((acc, post) => {
|
|
if(post.host && methods[post.host.method]) {
|
|
acc = acc.concat(methods[post.host.method](post).then(content => Object.assign(post, {content})).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 methods.redditPreview(post).then(content => Object.assign(post, {content}));
|
|
}
|
|
|
|
return null;
|
|
}));
|
|
} else {
|
|
console.log('\x1b[33m%s\x1b[0m', `Ignoring unsupported content '${post.url}' (${post.permalink})`);
|
|
}
|
|
|
|
return acc;
|
|
}, [])).then(posts => posts.filter(post => post));
|
|
};
|
|
|
|
module.exports = attachContentInfo;
|