diff --git a/src/index.js b/src/index.js index 4e89fe9..f816408 100644 --- a/src/index.js +++ b/src/index.js @@ -56,6 +56,7 @@ const PARAMS__HIDE = 'hide'; const PARAMS__LINK_ATTACHMENT = 'link_attachment'; const PARAMS__METRIC = 'metric'; const PARAMS__QUOTA_USAGE = 'quota_usage'; +const PARAMS__QUOTE_POST_ID = 'quote_post_id'; const PARAMS__REDIRECT_URI = 'redirect_uri'; const PARAMS__REPLY_CONFIG = 'reply_config'; const PARAMS__REPLY_CONTROL = 'reply_control'; @@ -293,23 +294,46 @@ app.get('/publishingLimit', loggedInUserChecker, async (req, res) => { }); app.get('/upload', loggedInUserChecker, (req, res) => { - const { replyToId } = req.query; + const { replyToId, quotePostId } = req.query; const title = replyToId === undefined ? 'Upload' : 'Upload (Reply)'; res.render('upload', { title, - replyToId + replyToId, + quotePostId, }); }); +app.post('/repost', upload.array(), async (req, res) => { + const { repostId } = req.body; + + const repostThreadsUrl = buildGraphAPIURL(`${repostId}/repost`, {}, req.session.access_token); + try { + const repostResponse = await axios.post(repostThreadsUrl, {}); + const containerId = repostResponse.data.id; + return res.redirect(`threads/${containerId}`); + } + catch (e) { + console.error(e.message); + return res.json({ + error: true, + message: `Error during repost: ${e}`, + }); + } +}); + app.post('/upload', upload.array(), async (req, res) => { - const { text, attachmentType, attachmentUrl, attachmentAltText, replyControl, replyToId, linkAttachment } = req.body; + const { text, attachmentType, attachmentUrl, attachmentAltText, replyControl, replyToId, linkAttachment, quotePostId } = req.body; const params = { [PARAMS__TEXT]: text, [PARAMS__REPLY_CONTROL]: replyControl, [PARAMS__REPLY_TO_ID]: replyToId, - [PARAMS__LINK_ATTACHMENT]: linkAttachment + [PARAMS__LINK_ATTACHMENT]: linkAttachment, }; + if (quotePostId) { + params[PARAMS__QUOTE_POST_ID] = quotePostId; + } + // No attachments if (!attachmentType?.length) { params.media_type = MEDIA_TYPE__TEXT; diff --git a/views/thread.pug b/views/thread.pug index 3a38c05..734f60c 100644 --- a/views/thread.pug +++ b/views/thread.pug @@ -44,3 +44,13 @@ block content td Insights td a(href=`/threads/${threadId}/insights`) View Insights + tr + td Quote + td + button(onclick=`location.href='/upload?quotePostId=${threadId}'`) Quote + tr + td Repost + td + form(action='/repost' method='post') + input(type='hidden' name='repostId' value=threadId) + button(type='submit') Repost diff --git a/views/upload.pug b/views/upload.pug index ce1cef1..379bf54 100644 --- a/views/upload.pug +++ b/views/upload.pug @@ -44,6 +44,10 @@ block content } #link-attachment { width: 200px; + margin-bottom: 15px; + } + #quote-post-id { + width: 200px; } if (replyToId !== undefined) @@ -71,6 +75,10 @@ block content | Link Attachment input#link-attachment(type='text' name='linkAttachment' value='') + if quotePostId + a(href=`/threads/${quotePostId}`) Quoting #{quotePostId} + input#quote-post-id(type='hidden' name='quotePostId' value=quotePostId) + input(type='hidden' name='replyToId' value=replyToId) input.threads-button(type='submit' id='submit' value='Post')