2024-09-11 03:16:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('config');
|
2024-09-11 03:16:53 +00:00
|
|
|
const util = require('util');
|
2024-09-11 03:16:53 +00:00
|
|
|
const yargs = require('yargs').argv;
|
|
|
|
const snoowrap = require('snoowrap');
|
2024-09-11 03:16:53 +00:00
|
|
|
const methods = require('./methods/methods.js');
|
2024-09-11 03:16:53 +00:00
|
|
|
const curate = require('./curate.js');
|
2024-09-11 03:16:53 +00:00
|
|
|
const fetchContent = require('./fetchContent.js');
|
2024-09-11 03:16:53 +00:00
|
|
|
|
2024-09-11 03:16:53 +00:00
|
|
|
const reddit = new snoowrap(config.reddit.api);
|
2024-09-11 03:16:53 +00:00
|
|
|
|
2024-09-11 03:16:53 +00:00
|
|
|
function getSubmissions(users) {
|
|
|
|
return users.reduce((chain, user) => {
|
|
|
|
return chain.then(acc => {
|
|
|
|
return reddit.getUser(user).getSubmissions({
|
|
|
|
sort: yargs.sort || config.reddit.sort,
|
|
|
|
limit: yargs.limit || config.reddit.limit
|
|
|
|
}).then(submissions => {
|
|
|
|
return acc.concat(submissions);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, Promise.resolve([]));
|
|
|
|
};
|
|
|
|
|
|
|
|
Promise.resolve().then(() => {
|
|
|
|
if(yargs.user || yargs.users) {
|
|
|
|
const users = yargs.users ? yargs.users.split(',') : [].concat(yargs.user);
|
|
|
|
|
|
|
|
return getSubmissions(users);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject('Please supply at least one user with one or multiple --user, or --users!');
|
2024-09-11 03:16:53 +00:00
|
|
|
}).then(submissions => {
|
2024-09-11 03:16:53 +00:00
|
|
|
return Promise.all(curate(submissions).reduce((acc, post) => {
|
2024-09-11 03:16:53 +00:00
|
|
|
if(post.host && methods[post.host.method]) {
|
|
|
|
acc = acc.concat(methods[post.host.method](post).then(content => {
|
|
|
|
post.content = content;
|
|
|
|
|
|
|
|
return post;
|
|
|
|
}));
|
|
|
|
} else {
|
2024-09-11 03:16:53 +00:00
|
|
|
console.log('\x1b[33m%s\x1b[0m', `"${post.title}": '${post.url}' not supported :(`);
|
2024-09-11 03:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, []));
|
2024-09-11 03:16:53 +00:00
|
|
|
}).then(posts => {
|
|
|
|
return fetchContent(posts);
|
|
|
|
}).catch(error => {
|
|
|
|
return console.log('\x1b[33m%s\x1b[0m', error);
|
2024-09-11 03:16:53 +00:00
|
|
|
});
|