Fetching and curating posts per user without merge.

This commit is contained in:
2018-06-10 02:48:49 +02:00
parent d56fff5082
commit aef4dd02c7
8 changed files with 68 additions and 30 deletions

9
src/curate/hashPost.js Normal file
View File

@@ -0,0 +1,9 @@
'use strict';
const crypto = require('crypto');
const hashPost = post => {
return crypto.createHash('md5').update(post.id + post.subreddit_id + post.created_utc + post.title).digest('hex');
};
module.exports = hashPost;

View File

@@ -3,11 +3,12 @@
const config = require('config');
const dissectLink = require('../dissectLink.js');
const omit = require('object.omit');
const hashPost = require('./hashPost.js');
const curatePosts = (userPosts, args) => {
const processed = new Set();
return Object.values(userPosts).reduce((accPosts, user) => accPosts.concat(user.posts.reduce((accUserPosts, post, index) => {
return Object.values(userPosts).reduce((accPosts, user) => ({...accPosts, [user.name]: {...user, posts: user.posts.reduce((accUserPosts, post, index) => {
// cut-off at limit, but don't count posts requested directly by ID
if(accUserPosts.length >= args.limit && !post.direct) {
return accUserPosts;
@@ -53,9 +54,10 @@ const curatePosts = (userPosts, args) => {
datetime: new Date(post.created_utc * 1000),
subreddit: post.subreddit.display_name,
preview: post.preview ? post.preview.images.map(image => image.source) : null,
host
host,
hash: hashPost(post)
});
}, [])), []);
}, [])}}), {});
};
module.exports = curatePosts;