44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const config = require('config');
|
|
const Promise = require('bluebird');
|
|
|
|
const methods = require('../methods/methods.js');
|
|
|
|
const attachContentInfo = users => 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.host, 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.host, post) }];
|
|
}
|
|
|
|
return accPosts;
|
|
}
|
|
}, []),
|
|
},
|
|
}), {});
|
|
|
|
async function getInfo(host) {
|
|
return methods[host.method](host);
|
|
}
|
|
|
|
module.exports = {
|
|
attachContentInfo,
|
|
getInfo,
|
|
};
|