From 693d2fda691e4bfe54470e1e48eb8b0d1605a299 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Mon, 23 Jun 2025 22:42:21 -0600 Subject: [PATCH] fedimbed: revert, this broke entirely somehow --- src/modules/fedimbed.js | 42 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index fb7e077..5f26bce 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -1,7 +1,6 @@ const fs = require("node:fs"); const httpSignature = require("@peertube/http-signature"); const {XMLParser} = require("fast-xml-parser"); -const {ProxyAgent} = require("undici"); const events = require("#lib/events.js"); const logger = require("#lib/logger.js"); @@ -22,7 +21,6 @@ const BSKY_POST_REGEX = /^\/profile\/(did:plc:[a-z0-9]+|(did:web:)?[a-z0-9][a-z0-9.-]+[a-z0-9]*)\/post\/([a-z0-9]+)\/?$/i; const PATH_REGEX = { - truthsocial: /^\/@(.+?)\/posts\/(\d+)\/?/i, mastodon: /^\/@(.+?)\/([a-z0-9]+?)\/?/i, mastodon2: /^\/(.+?)\/statuses\/([a-z0-9]+?)\/?/i, pleroma: /^\/objects\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/?/, @@ -114,16 +112,6 @@ const numberFormatter = Intl.NumberFormat("en-US"); const domainCache = new Map(); domainCache.set("cohost.org", "cohost"); // no nodeinfo -domainCache.set("truthsocial.com", "Truth Social"); // no nodeinfo - -const proxyAgent = new ProxyAgent(hf.config.proxy); - -function firefoxUseragent() { - const now = Math.floor(Date.now() / 1000); - const version = Math.floor(124 + (now - 1710892800) / 2419200); - - return `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:${version}.0) Gecko/20100101 Firefox/${version}.0`; -} async function resolvePlatform(url) { const urlObj = new URL(url); @@ -183,9 +171,8 @@ async function getCrawledData(url, color, platformName) { try { const page = await fetch(url, { headers: { - "User-Agent": urlObj.hostname === "truthsocial.com" ? firefoxUseragent() : FRIENDLY_USERAGENT, + "User-Agent": FRIENDLY_USERAGENT, }, - dispatcher: urlObj.hostname === "truthsocial.com" ? proxyAgent : null, }) .then((res) => res.text()) .catch(() => {}); @@ -774,17 +761,15 @@ async function bluesky(msg, url, spoiler = false, minimal = false) { async function fetchPost(url, platform, forceMastoAPI = false) { let urlObj = new URL(url); let postData; - const ffua = firefoxUseragent(); if (!forceMastoAPI) { let rawPostData; try { rawPostData = await signedFetch(url, { headers: { - "User-Agent": urlObj.hostname === "truthsocial.com" ? ffua : FRIENDLY_USERAGENT, + "User-Agent": FRIENDLY_USERAGENT, Accept: "application/activity+json", }, - dispatcher: urlObj.hostname === "truthsocial.com" ? proxyAgent : null, }).then((res) => res.text()); } catch (err) { logger.error("fedimbed", `Failed to signed fetch "${url}", retrying unsigned: ${err}`); @@ -793,10 +778,9 @@ async function fetchPost(url, platform, forceMastoAPI = false) { try { rawPostData = await fetch(url, { headers: { - "User-Agent": urlObj.hostname === "truthsocial.com" ? ffua : FRIENDLY_USERAGENT, + "User-Agent": FRIENDLY_USERAGENT, Accept: "application/activity+json", }, - dispatcher: urlObj.hostname === "truthsocial.com" ? proxyAgent : null, }).then((res) => res.text()); } catch (err) { logger.error("fedimbed", `Failed to fetch "${url}": ${err}`); @@ -840,10 +824,7 @@ async function fetchPost(url, platform, forceMastoAPI = false) { let redirUrl; const options = {}; const headers = {}; - if (urlObj.hostname === "truthsocial.com") { - const postId = urlObj.pathname.match(PATH_REGEX.truthsocial)?.[2]; - redirUrl = urlObj.origin + "/api/v1/statuses/" + postId; - } else 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)) { const postId = urlObj.pathname.match(PATH_REGEX.mastodon)?.[2]; @@ -886,9 +867,8 @@ async function fetchPost(url, platform, forceMastoAPI = false) { redirUrl, Object.assign(options, { headers: Object.assign(headers, { - "User-Agent": urlObj.hostname === "truthsocial.com" ? ffua : FRIENDLY_USERAGENT, + "User-Agent": FRIENDLY_USERAGENT, }), - dispatcher: urlObj.hostname === "truthsocial.com" ? proxyAgent : null, }) ).then((res) => res.text()); } catch (err) { @@ -900,9 +880,8 @@ async function fetchPost(url, platform, forceMastoAPI = false) { redirUrl, Object.assign(options, { headers: Object.assign(headers, { - "User-Agent": urlObj.hostname === "truthsocial.com" ? ffua : FRIENDLY_USERAGENT, + "User-Agent": FRIENDLY_USERAGENT, }), - dispatcher: urlObj.hostname === "truthsocial.com" ? proxyAgent : null, }) ).then((res) => res.text()); } catch (err) { @@ -939,28 +918,23 @@ async function fetchPost(url, platform, forceMastoAPI = false) { } async function getStatsAS(post) { - const urlObj = new URL(post); - const ffua = firefoxUseragent(); - // agony let replyCount = 0; if (post?.replies?.id) try { const selfReplies = await signedFetch(post.replies.id + "?page=true", { headers: { - "User-Agent": urlObj.hostname === "truthsocial.com" ? ffua : FRIENDLY_USERAGENT, + "User-Agent": FRIENDLY_USERAGENT, Accept: "application/activity+json", }, - dispatcher: urlObj.hostname === "truthsocial.com" ? proxyAgent : null, }).then((res) => res.json()); replyCount += selfReplies?.items?.length ?? 0; const otherReplies = await signedFetch(post.replies.id + "?page=true&only_other_accounts=true", { headers: { - "User-Agent": urlObj.hostname === "truthsocial.com" ? ffua : FRIENDLY_USERAGENT, + "User-Agent": FRIENDLY_USERAGENT, Accept: "application/activity+json", }, - dispatcher: urlObj.hostname === "truthsocial.com" ? proxyAgent : null, }).then((res) => res.json()); replyCount += otherReplies?.items?.length ?? 0; } catch {