56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
function curateComments(comments) {
|
|
return comments.map(comment => ({
|
|
id: comment.id,
|
|
url: `https://reddit.com${comment.permalink}`,
|
|
author: comment.author.name,
|
|
body: comment.body,
|
|
html: comment.body_html,
|
|
score: comment.score,
|
|
datetime: new Date(comment.created * 1000),
|
|
edited: comment.edited,
|
|
controversiality: comment.controversiality,
|
|
gilded: comment.gilded,
|
|
stickied: comment.stickied,
|
|
distinguished: comment.distinguished,
|
|
locked: comment.locked,
|
|
archived: comment.archived,
|
|
parent: comment.parent_id,
|
|
replies: comment.replies ? curateComments(comment.replies) : [],
|
|
}));
|
|
}
|
|
|
|
async function getFullPost(postId, reddit) {
|
|
return reddit
|
|
.getSubmission(postId)
|
|
.expandReplies({
|
|
limit: Infinity,
|
|
depth: Infinity,
|
|
})
|
|
.fetch();
|
|
}
|
|
|
|
async function self(host, originalPost, reddit) {
|
|
const post = await getFullPost(originalPost.id, reddit) || originalPost;
|
|
const curatedComments = curateComments(post.comments);
|
|
|
|
return {
|
|
album: null,
|
|
items: [{
|
|
id: post.id,
|
|
url: post.url,
|
|
title: post.title,
|
|
text: post.text,
|
|
author: post.author.name,
|
|
datetime: post.datetime,
|
|
comments: curatedComments,
|
|
type: 'text/plain',
|
|
self: true,
|
|
original: post,
|
|
}],
|
|
};
|
|
}
|
|
|
|
module.exports = self;
|