43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const config = require('config');
|
|
const util = require('util');
|
|
const note = require('note-log');
|
|
const yargs = require('yargs').argv;
|
|
const snoowrap = require('snoowrap');
|
|
const methods = require('./methods/methods.js');
|
|
const dissectLink = require('./dissectLink.js');
|
|
const fetchContent = require('./fetchContent.js');
|
|
|
|
const reddit = new snoowrap(config.api);
|
|
|
|
reddit.getUser(yargs.user).getSubmissions({
|
|
sort: 'top'
|
|
}).then(submissions => {
|
|
const curatedPosts = submissions.map(submission => {
|
|
return {
|
|
id: submission.id,
|
|
title: submission.title,
|
|
permalink: submission.permalink,
|
|
url: submission.url,
|
|
host: dissectLink(submission.url)
|
|
};
|
|
});
|
|
|
|
return Promise.all(curatedPosts.reduce((acc, post) => {
|
|
if(post.host && methods[post.host.method]) {
|
|
acc = acc.concat(methods[post.host.method](post).then(content => {
|
|
post.content = content;
|
|
|
|
return post;
|
|
}));
|
|
} else {
|
|
note('fetch', 1, `"${post.title}": '${post.url}' not supported :(`);
|
|
}
|
|
|
|
return acc;
|
|
}, []));
|
|
}).then(fetchContent).catch(error => {
|
|
note(error);
|
|
});
|