fedimbed: fixes for mastodon redir

This commit is contained in:
Cynthia Foxwell 2022-12-05 21:46:03 -07:00
parent ce90b0ca86
commit 7087a9bae5
1 changed files with 19 additions and 19 deletions

View File

@ -131,14 +131,11 @@ async function processUrl(msg, url) {
if (redirUrl) {
logger.verbose("fedimbed", `Redirecting "${url}" to "${redirUrl}"`);
const rawPostData2 = await fetch(
redirUrl,
{
headers: {
"User-Agent": FRIENDLY_USERAGENT,
},
}
)
const rawPostData2 = await fetch(redirUrl, {
headers: {
"User-Agent": FRIENDLY_USERAGENT,
},
})
.then((res) => res.text())
.catch((err) => {
logger.error(
@ -151,7 +148,10 @@ async function processUrl(msg, url) {
if (rawPostData2.startsWith("{")) {
postData2 = JSON.parse(rawPostData2);
} else {
logger.warn("fedimbed", `Got non-JSON for "${url}" as MastoAPI: ${rawPostData2}`);
logger.warn(
"fedimbed",
`Got non-JSON for "${url}" as MastoAPI: ${rawPostData2}`
);
}
if (!postData2) {
@ -165,14 +165,14 @@ async function processUrl(msg, url) {
`Bailing trying to re-embed "${url}", MastoAPI gave us error: ${postData2.error}`
);
} else {
cw = postData2.spoiler_warning;
cw = postData2.spoiler_warning ?? postData2.spoiler_text;
content =
postData2.akkoma?.source?.content ??
postData2.pleroma?.content?.["text/plain"] ??
postData2.content;
author = {
name: postData2.account.display_name,
handle: postData2.account.fqn,
handle: postData2.account.fqn ?? `${postData2.account.username}@${urlObj.hostname}`,
url: postData2.account.url,
avatar: postData2.account.avatar,
};
@ -289,13 +289,13 @@ async function processUrl(msg, url) {
const embeds = [];
if (attachments.length > 0) {
for (const attachment of attachments) {
const embed = Object.assign({}, baseEmbed);
embed.image = {
url: attachment.url,
};
embeds.push(embed);
}
for (const attachment of attachments) {
const embed = Object.assign({}, baseEmbed);
embed.image = {
url: attachment.url,
};
embeds.push(embed);
}
} else {
embeds.push(baseEmbed);
}
@ -313,7 +313,7 @@ async function processUrl(msg, url) {
.catch(() => {});
await msg.channel.createMessage({
content: cw && attachments.length > 0 ? ":warning: " + cw + " || ||": "",
content: cw && attachments.length > 0 ? ":warning: " + cw + " || ||" : "",
embeds,
allowedMentions: {
repliedUser: false,