Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions views/thread.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions views/upload.pug
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ block content
}
#link-attachment {
width: 200px;
margin-bottom: 15px;
}
#quote-post-id {
width: 200px;
}

if (replyToId !== undefined)
Expand Down Expand Up @@ -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')

Expand Down