fedimbed: fallback to unsigned if signed fails
temp workaround for firefish
This commit is contained in:
parent
967a7f7bc8
commit
5d8153588f
1 changed files with 38 additions and 10 deletions
|
@ -115,19 +115,32 @@ async function processUrl(msg, url, spoiler = false) {
|
|||
let content, cw, author, timestamp;
|
||||
|
||||
// Fetch post
|
||||
const rawPostData = await signedFetch(url, {
|
||||
let rawPostData = await signedFetch(url, {
|
||||
headers: {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
Accept: "application/activity+json",
|
||||
},
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.catch((err) => {
|
||||
logger.error("fedimbed", `Failed to fetch "${url}" as AS2: ${err}`);
|
||||
.catch(async (err) => {
|
||||
logger.error(
|
||||
"fedimbed",
|
||||
`Failed to signed fetch "${url}", retrying unsigned: ${err}`
|
||||
);
|
||||
rawPostData = await fetch(url, {
|
||||
headers: {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
Accept: "application/activity+json",
|
||||
},
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.catch((err) => {
|
||||
logger.error("fedimbed", `Failed to fetch "${url}": ${err}`);
|
||||
});
|
||||
});
|
||||
|
||||
let postData;
|
||||
if (rawPostData.startsWith("{")) {
|
||||
if (rawPostData?.startsWith("{")) {
|
||||
postData = JSON.parse(rawPostData);
|
||||
} else {
|
||||
logger.warn("fedimbed", `Got non-JSON for "${url}": ${rawPostData}`);
|
||||
|
@ -194,7 +207,7 @@ async function processUrl(msg, url, spoiler = false) {
|
|||
options
|
||||
)}, ${JSON.stringify(headers)}`
|
||||
);
|
||||
const rawPostData2 = await signedFetch(
|
||||
let rawPostData2 = await signedFetch(
|
||||
redirUrl,
|
||||
Object.assign(options, {
|
||||
headers: Object.assign(headers, {
|
||||
|
@ -203,27 +216,42 @@ async function processUrl(msg, url, spoiler = false) {
|
|||
})
|
||||
)
|
||||
.then((res) => res.text())
|
||||
.catch((err) => {
|
||||
.catch(async (err) => {
|
||||
logger.error(
|
||||
"fedimbed",
|
||||
`Failed to fetch "${url}" as MastoAPI: ${err}`
|
||||
`Failed to signed fetch "${url}" via MastoAPI, retrying unsigned: ${err}`
|
||||
);
|
||||
rawPostData2 = await signedFetch(
|
||||
redirUrl,
|
||||
Object.assign(options, {
|
||||
headers: Object.assign(headers, {
|
||||
"User-Agent": FRIENDLY_USERAGENT,
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then((res) => res.text())
|
||||
.catch((err) => {
|
||||
logger.error(
|
||||
"fedimbed",
|
||||
`Failed to fetch "${url}" via MastoAPI: ${err}`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
let postData2;
|
||||
if (rawPostData2.startsWith("{")) {
|
||||
if (rawPostData2?.startsWith("{")) {
|
||||
postData2 = JSON.parse(rawPostData2);
|
||||
} else {
|
||||
logger.warn(
|
||||
"fedimbed",
|
||||
`Got non-JSON for "${url}" as MastoAPI: ${rawPostData2}`
|
||||
`Got non-JSON for "${url}" via MastoAPI: ${rawPostData2}`
|
||||
);
|
||||
}
|
||||
|
||||
if (!postData2) {
|
||||
logger.warn(
|
||||
"fedimbed",
|
||||
`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 normal and MastoAPI.`
|
||||
);
|
||||
} else if (postData2.error) {
|
||||
logger.error(
|
||||
|
|
Loading…
Reference in a new issue