fedimbed: add AFM fallback to mastodon
This commit is contained in:
parent
70f8d71593
commit
c689c7c5d5
1 changed files with 17 additions and 7 deletions
|
@ -97,7 +97,7 @@ async function processUrl(msg, url) {
|
||||||
|
|
||||||
if (!postData) {
|
if (!postData) {
|
||||||
// We failed to get post.
|
// 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)) {
|
if (PATH_REGEX.pleroma.test(urlObj.pathname)) {
|
||||||
url = await fetch(url, {
|
url = await fetch(url, {
|
||||||
method: "HEAD",
|
method: "HEAD",
|
||||||
|
@ -112,7 +112,19 @@ async function processUrl(msg, url) {
|
||||||
urlObj = new URL(url);
|
urlObj = new URL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let redirUrl;
|
||||||
if (PATH_REGEX.pleroma2.test(urlObj.pathname)) {
|
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"), {
|
const postData2 = await fetch(url.replace("notice", "api/v1/statuses"), {
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": FRIENDLY_USERAGENT,
|
"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.`
|
`Bailing trying to re-embed "${url}": Failed to get post from both AS2 and MastoAPI.`
|
||||||
);
|
);
|
||||||
} else if (postData2.error) {
|
} 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 {
|
} else {
|
||||||
cw = postData2.spoiler_warning;
|
cw = postData2.spoiler_warning;
|
||||||
content =
|
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 {
|
} else {
|
||||||
content = postData.content;
|
content = postData.content;
|
||||||
|
|
Loading…
Reference in a new issue