diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index 7a85f07..32fc6aa 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -97,7 +97,7 @@ async function processUrl(msg, url) { if (!postData) { // We failed to get post. - // If we're fetching from Pleroma, assume it was due to AMF and use MastoAPI + // If we're fetching from Pleroma, assume it was due to AFM and use MastoAPI if (PATH_REGEX.pleroma.test(urlObj.pathname)) { url = await fetch(url, { method: "HEAD", @@ -112,7 +112,19 @@ async function processUrl(msg, url) { urlObj = new URL(url); } + let redirUrl; if (PATH_REGEX.pleroma2.test(urlObj.pathname)) { + redirUrl = url.replace("notice", "api/v1/statuses"); + } else if (PATH_REGEX.mastodon.test(urlObj.pathName)) { + redirUrl = url.replace(/@(.+?)\//, "api/v1/statuses/"); + } else { + logger.error( + "fedimbed", + `Missing MastoAPI replacement for "${platform}"` + ); + } + + if (redirUrl) { const postData2 = await fetch(url.replace("notice", "api/v1/statuses"), { headers: { "User-Agent": FRIENDLY_USERAGENT, @@ -132,7 +144,10 @@ async function processUrl(msg, url) { `Bailing trying to re-embed "${url}": Failed to get post from both AS2 and MastoAPI.` ); } else if (postData2.error) { - logger.error("fedimbed", `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${postData2.error}`); + logger.error( + "fedimbed", + `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${postData2.error}` + ); } else { cw = postData2.spoiler_warning; content = @@ -153,11 +168,6 @@ async function processUrl(msg, url) { }); } } - } else { - logger.error( - "fedimbed", - `Redirect from /object did not give us /notice. (${urlObj.pathname})` - ); } } else { content = postData.content;