fedimbed: fixes for mastodon redir

This commit is contained in:
Cynthia Foxwell 2022-12-05 21:46:03 -07:00
parent ce90b0ca86
commit 7087a9bae5

View file

@ -131,14 +131,11 @@ async function processUrl(msg, url) {
if (redirUrl) { if (redirUrl) {
logger.verbose("fedimbed", `Redirecting "${url}" to "${redirUrl}"`); logger.verbose("fedimbed", `Redirecting "${url}" to "${redirUrl}"`);
const rawPostData2 = await fetch( const rawPostData2 = await fetch(redirUrl, {
redirUrl,
{
headers: { headers: {
"User-Agent": FRIENDLY_USERAGENT, "User-Agent": FRIENDLY_USERAGENT,
}, },
} })
)
.then((res) => res.text()) .then((res) => res.text())
.catch((err) => { .catch((err) => {
logger.error( logger.error(
@ -151,7 +148,10 @@ async function processUrl(msg, url) {
if (rawPostData2.startsWith("{")) { if (rawPostData2.startsWith("{")) {
postData2 = JSON.parse(rawPostData2); postData2 = JSON.parse(rawPostData2);
} else { } 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) { if (!postData2) {
@ -165,14 +165,14 @@ async function processUrl(msg, url) {
`Bailing trying to re-embed "${url}", MastoAPI gave us error: ${postData2.error}` `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${postData2.error}`
); );
} else { } else {
cw = postData2.spoiler_warning; cw = postData2.spoiler_warning ?? postData2.spoiler_text;
content = content =
postData2.akkoma?.source?.content ?? postData2.akkoma?.source?.content ??
postData2.pleroma?.content?.["text/plain"] ?? postData2.pleroma?.content?.["text/plain"] ??
postData2.content; postData2.content;
author = { author = {
name: postData2.account.display_name, name: postData2.account.display_name,
handle: postData2.account.fqn, handle: postData2.account.fqn ?? `${postData2.account.username}@${urlObj.hostname}`,
url: postData2.account.url, url: postData2.account.url,
avatar: postData2.account.avatar, avatar: postData2.account.avatar,
}; };