Files
ripunzel/src/methods/self.js

50 lines
1.4 KiB
JavaScript

'use strict';
function curateComments(comments) {
return comments.map((comment) => ({
id: comment.id,
url: `https://reddit.com${comment.permalink}`,
author: comment.author,
body: comment.body,
html: comment.body_html,
score: comment.score,
datetime: new Date(comment.created_utc * 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.getSubmissionWithComments(postId);
}
async function self(host, originalPost, { reddit }) {
const { post, comments } = await getFullPost(originalPost.id, reddit);
const curatedComments = curateComments(comments);
return {
album: null,
items: [{
id: post.id,
url: post.url,
title: post.title,
text: post.selftext,
author: post.author,
datetime: new Date(post.created_utc * 1000),
comments: curatedComments,
type: 'text/plain',
self: true,
original: post,
}],
};
}
module.exports = self;