From 5851a5a51d681f57ca3d9aa9cdcec868fe8f194a Mon Sep 17 00:00:00 2001 From: Cynthia Date: Sat, 31 Dec 2022 12:59:21 -0700 Subject: [PATCH] fedimbed: set headers if posting --- src/modules/fedimbed.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index eb7a2bc..a10b05a 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -118,6 +118,7 @@ async function processUrl(msg, url) { let redirUrl; const options = {}; + const headers = {}; if (PATH_REGEX.pleroma2.test(urlObj.pathname)) { redirUrl = url.replace("notice", "api/v1/statuses"); } else if (PATH_REGEX.mastodon.test(urlObj.pathname)) { @@ -130,6 +131,7 @@ async function processUrl(msg, url) { redirUrl = urlObj.origin + "/api/notes/show/"; options.method = "POST"; options.body = JSON.stringify({noteId}); + headers["Content-Type"] = "application/json"; } else { logger.error( "fedimbed", @@ -141,14 +143,11 @@ async function processUrl(msg, url) { logger.verbose("fedimbed", `Redirecting "${url}" to "${redirUrl}"`); const rawPostData2 = await fetch( redirUrl, - Object.assign( - { - headers: { - "User-Agent": FRIENDLY_USERAGENT, - }, - }, - options - ) + Object.assign(options, { + headers: Object.assign(headers, { + "User-Agent": FRIENDLY_USERAGENT, + }), + }) ) .then((res) => res.text()) .catch((err) => { @@ -176,7 +175,9 @@ async function processUrl(msg, url) { } else if (postData2.error) { logger.error( "fedimbed", - `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${JSON.stringify(postData2.error)}` + `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${JSON.stringify( + postData2.error + )}` ); } else { cw =