From a7ca9fd347059201d83b618388dfb7fec053fd3d Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sun, 7 Jan 2024 13:10:10 -0700 Subject: [PATCH] fedimbed: cohost support --- src/modules/fedimbed.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index a3b8efe..4e77f7b 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -24,7 +24,8 @@ const PATH_REGEX = { misskey: /^\/notes\/[a-z0-9]+\/?/, gotosocial: /^\/@(.+?)\/statuses\/[0-9A-Z]+\/?/, lemmy: /^\/post\/\d+\/?/, - honk: /^\/u\/(.+?)\/h\/(.+?)\/?$/, + honk: /^\/u\/(.+?)\/h\/(.+?)\/?/, + cohost: /^\/[A-Za-z0-9]+\/post\/\d+-[A-Za-z0-9-]+\/?/, }; const PLATFORM_COLORS = { @@ -38,9 +39,12 @@ const PLATFORM_COLORS = { lemmy: 0x14854f, birdsitelive: 0x1da1f2, iceshrimp: 0x8e82f9, // YCbCr interpolated as the accent color is a gradient + cohost: 0x83254f, }; const domainCache = new Map(); +domainCache.set("cohost.org", "cohost"); // no nodeinfo + async function resolvePlatform(url) { const urlObj = new URL(url); if (domainCache.has(urlObj.hostname)) return domainCache.get(urlObj.hostname); @@ -137,7 +141,8 @@ async function processUrl(msg, url, spoiler = false) { let platformName = platform .replace("gotosocial", "GoToSocial") .replace("birdsitelive", '"Twitter" (BirdsiteLive)') - .replace(/^(.)/, (_, c) => c.toUpperCase()); + .replace(/^(.)/, (_, c) => c.toUpperCase()) + .replace("Cohost", "cohost"); const images = []; const videos = []; @@ -475,7 +480,9 @@ async function processUrl(msg, url, spoiler = false) { ) .then((res) => res.json()) .catch((err) => { - logger.error("fedimbed", `Failed to get author for "${url}": ${err}`); + // only posts can be activity+json right now, reduce log spam + if (platform !== "cohost") + logger.error("fedimbed", `Failed to get author for "${url}": ${err}`); }); if (authorData) { @@ -486,6 +493,18 @@ async function processUrl(msg, url, spoiler = false) { url: authorData.url, avatar: authorData.icon?.url, }; + } else { + // bootleg author, mainly for cohost + const authorUrl = postData.actor ?? postData.attributedTo; + const authorUrlObj = new URL(authorUrl); + const name = authorUrlObj.pathname.substring( + authorUrlObj.pathname.lastIndexOf("/") + 1 + ); + author = { + name, + handle: `${name}@${authorUrlObj.hostname}`, + url: authorUrl, + }; } if (postData.endTime && postData.oneOf && postData.votersCount) { @@ -515,6 +534,10 @@ async function processUrl(msg, url, spoiler = false) { // FIXME: stop being lazy and use an html parser content = content.replace(/(.+?)<\/a>/g, "[$2]($1)"); + content = content.replace( + //g, + "[$2]($1)" + ); content = content.replace(/<\/?\s*br\s*\/?>/g, "\n"); content = content.replace(/<\/p>

/g, "\n\n"); content = content.replace(/

    /g, "\n");