Fetching and curating posts per user without merge.
This commit is contained in:
9
src/curate/hashPost.js
Normal file
9
src/curate/hashPost.js
Normal 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;
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user