fedimbed: set headers if posting

This commit is contained in:
Cynthia Foxwell 2022-12-31 12:59:21 -07:00
parent f96ee62da7
commit 5851a5a51d
1 changed files with 10 additions and 9 deletions

View File

@ -118,6 +118,7 @@ async function processUrl(msg, url) {
let redirUrl; let redirUrl;
const options = {}; const options = {};
const headers = {};
if (PATH_REGEX.pleroma2.test(urlObj.pathname)) { if (PATH_REGEX.pleroma2.test(urlObj.pathname)) {
redirUrl = url.replace("notice", "api/v1/statuses"); redirUrl = url.replace("notice", "api/v1/statuses");
} else if (PATH_REGEX.mastodon.test(urlObj.pathname)) { } else if (PATH_REGEX.mastodon.test(urlObj.pathname)) {
@ -130,6 +131,7 @@ async function processUrl(msg, url) {
redirUrl = urlObj.origin + "/api/notes/show/"; redirUrl = urlObj.origin + "/api/notes/show/";
options.method = "POST"; options.method = "POST";
options.body = JSON.stringify({noteId}); options.body = JSON.stringify({noteId});
headers["Content-Type"] = "application/json";
} else { } else {
logger.error( logger.error(
"fedimbed", "fedimbed",
@ -141,14 +143,11 @@ async function processUrl(msg, url) {
logger.verbose("fedimbed", `Redirecting "${url}" to "${redirUrl}"`); logger.verbose("fedimbed", `Redirecting "${url}" to "${redirUrl}"`);
const rawPostData2 = await fetch( const rawPostData2 = await fetch(
redirUrl, redirUrl,
Object.assign( Object.assign(options, {
{ headers: Object.assign(headers, {
headers: { "User-Agent": FRIENDLY_USERAGENT,
"User-Agent": FRIENDLY_USERAGENT, }),
}, })
},
options
)
) )
.then((res) => res.text()) .then((res) => res.text())
.catch((err) => { .catch((err) => {
@ -176,7 +175,9 @@ async function processUrl(msg, url) {
} else if (postData2.error) { } else if (postData2.error) {
logger.error( logger.error(
"fedimbed", "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 { } else {
cw = cw =